Skip to content

Commit a943a14

Browse files
committed
go/analysis/passes/directive: do not report adjoining //go:debug
Fixes golang/go#66046 Change-Id: I5fc8a2370c46b5d35df9759d3632b7659685aa5c Reviewed-on: https://go-review.googlesource.com/c/tools/+/569360 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent b020bdb commit a943a14

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

go/analysis/passes/directive/directive.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ func checkGoFile(pass *analysis.Pass, f *ast.File) {
7070
check := newChecker(pass, pass.Fset.File(f.Package).Name(), f)
7171

7272
for _, group := range f.Comments {
73-
// A +build comment is ignored after or adjoining the package declaration.
74-
if group.End()+1 >= f.Package {
75-
check.inHeader = false
76-
}
77-
// A //go:build comment is ignored after the package declaration
73+
// A //go:build or a //go:debug comment is ignored after the package declaration
7874
// (but adjoining it is OK, in contrast to +build comments).
7975
if group.Pos() >= f.Package {
8076
check.inHeader = false
@@ -104,8 +100,7 @@ type checker struct {
104100
pass *analysis.Pass
105101
filename string
106102
file *ast.File // nil for non-Go file
107-
inHeader bool // in file header (before package declaration)
108-
inStar bool // currently in a /* */ comment
103+
inHeader bool // in file header (before or adjoining package declaration)
109104
}
110105

111106
func newChecker(pass *analysis.Pass, filename string, file *ast.File) *checker {

go/analysis/passes/directive/directive_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
package directive_test
66

77
import (
8-
"runtime"
9-
"strings"
108
"testing"
119

1210
"golang.org/x/tools/go/analysis"
1311
"golang.org/x/tools/go/analysis/analysistest"
1412
"golang.org/x/tools/go/analysis/passes/directive"
13+
"golang.org/x/tools/internal/testenv"
1514
)
1615

1716
func Test(t *testing.T) {
18-
if strings.HasPrefix(runtime.Version(), "go1.") && runtime.Version() < "go1.16" {
19-
t.Skipf("skipping on %v", runtime.Version())
20-
}
17+
testenv.NeedsGo1Point(t, 16)
2118
analyzer := *directive.Analyzer
2219
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
2320
defer func() {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build ignore
6+
7+
//go:debug panicnil=1
8+
package main

0 commit comments

Comments
 (0)