go.tools/oracle: fix bug in reduceScope on ad-hoc main packages.
LGTM=crawshaw R=crawshaw CC=golang-codereviews https://golang.org/cl/77450048
This commit is contained in:
parent
6256e2d81b
commit
a4491f08bf
|
@ -303,14 +303,13 @@ func reduceScope(pos string, conf *loader.Config) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return // no files for package
|
return // no files for package
|
||||||
}
|
}
|
||||||
_ = bp
|
|
||||||
|
|
||||||
// TODO(adonovan): fix: also check that the queried file appears in the package.
|
// Check that the queried file appears in the package:
|
||||||
// for _, f := range bp.GoFiles, bp.TestGoFiles, bp.XTestGoFiles {
|
// it might be a '// +build ignore' from an ad-hoc main
|
||||||
// if sameFile(f, fqpos.filename) { goto found }
|
// package, e.g. $GOROOT/src/pkg/net/http/triv.go.
|
||||||
// }
|
if !pkgContainsFile(bp, fqpos.fset.File(fqpos.start).Name()) {
|
||||||
// return // not found
|
return // not found
|
||||||
// found:
|
}
|
||||||
|
|
||||||
conf.TypeCheckFuncBodies = func(p string) bool { return p == importPath }
|
conf.TypeCheckFuncBodies = func(p string) bool { return p == importPath }
|
||||||
|
|
||||||
|
@ -325,6 +324,17 @@ func reduceScope(pos string, conf *loader.Config) {
|
||||||
_ = conf.ImportWithTests(importPath) // ignore error
|
_ = conf.ImportWithTests(importPath) // ignore error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pkgContainsFile(bp *build.Package, filename string) bool {
|
||||||
|
for _, files := range [][]string{bp.GoFiles, bp.TestGoFiles, bp.XTestGoFiles} {
|
||||||
|
for _, file := range files {
|
||||||
|
if sameFile(file, filename) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// New constructs a new Oracle that can be used for a sequence of queries.
|
// New constructs a new Oracle that can be used for a sequence of queries.
|
||||||
//
|
//
|
||||||
// iprog specifies the program to analyze.
|
// iprog specifies the program to analyze.
|
||||||
|
|
Loading…
Reference in New Issue