mirror of
https://github.com/golang/go
synced 2024-11-18 18:54:42 -07:00
go/analysis/unitchecker: use importer.ForCompiler under go1.12
importer.For does not populate the caller's token.FileSet leading to spurious position information in diagnostics. This change is the upstream fix for https://go-review.googlesource.com/c/go/+/152258. Fixes golang/go#28995 Change-Id: I9307d4f1f25c2b0877558426d4d71b3f1df99505 Reviewed-on: https://go-review.googlesource.com/c/152578 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
e5f3ab76ea
commit
47a17e0312
@ -181,6 +181,11 @@ func readConfig(filename string) (*Config, error) {
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var importerForCompiler = func(_ *token.FileSet, compiler string, lookup importer.Lookup) types.Importer {
|
||||||
|
// broken legacy implementation (github.com/golang/go/issues/28995)
|
||||||
|
return importer.For(compiler, lookup)
|
||||||
|
}
|
||||||
|
|
||||||
func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]result, error) {
|
func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]result, error) {
|
||||||
// Load, parse, typecheck.
|
// Load, parse, typecheck.
|
||||||
var files []*ast.File
|
var files []*ast.File
|
||||||
@ -196,7 +201,7 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
|
|||||||
}
|
}
|
||||||
files = append(files, f)
|
files = append(files, f)
|
||||||
}
|
}
|
||||||
compilerImporter := importer.For(cfg.Compiler, func(path string) (io.ReadCloser, error) {
|
compilerImporter := importerForCompiler(fset, cfg.Compiler, func(path string) (io.ReadCloser, error) {
|
||||||
// path is a resolved package path, not an import path.
|
// path is a resolved package path, not an import path.
|
||||||
file, ok := cfg.PackageFile[path]
|
file, ok := cfg.PackageFile[path]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
9
go/analysis/unitchecker/unitchecker112.go
Normal file
9
go/analysis/unitchecker/unitchecker112.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// +build go1.12
|
||||||
|
|
||||||
|
package unitchecker
|
||||||
|
|
||||||
|
import "go/importer"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
importerForCompiler = importer.ForCompiler
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user