1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -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:
Alan Donovan 2018-12-04 13:07:17 -05:00
parent e5f3ab76ea
commit 47a17e0312
2 changed files with 15 additions and 1 deletions

View File

@ -181,6 +181,11 @@ func readConfig(filename string) (*Config, error) {
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) {
// Load, parse, typecheck.
var files []*ast.File
@ -196,7 +201,7 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
}
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.
file, ok := cfg.PackageFile[path]
if !ok {

View File

@ -0,0 +1,9 @@
// +build go1.12
package unitchecker
import "go/importer"
func init() {
importerForCompiler = importer.ForCompiler
}