-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
Reproducer (using the x/tools/go/packages testing API):
func TestReproducer(t *testing.T) {
exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{
{
Name: "test",
Files: map[string]any{
"test.go": `package test; import "test/other"; var _ = other.Test;`,
"other/file.go": `package other
//line other.go:1:1
var Test int
`,
},
},
})
t.Cleanup(exported.Cleanup)
exported.Config.Mode = packages.LoadSyntax
exported.Config.Fset = token.NewFileSet()
pkgs, err := packages.Load(exported.Config, "test")
if err != nil {
t.Fatal(err)
}
packages.PrintErrors(pkgs)
p := pkgs[0].Imports["test/other"]
pos := p.Types.Scope().Lookup("Test").Pos()
t.Log(exported.Config.Fset.Position(pos)) // other.go:4:1
}The Mode is set to packages.LoadSyntax, thus go/packages is going to load test/other from the ExportFile.
$ go test ./go/packages/ -run TestReproducer -v
=== RUN TestReproducer
(....)
packages_test.go:3455: other.go:4:1
--- PASS: TestReproducer (0.15s)The file name (other.go) comes from the line directive, but the line/col (4:1) information does not.
I think that the issue is somewhere in cmd/go, while debugging, i saw the same values here (i.e. other.go:4:1):
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
Status
Todo