golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.73k stars 17.62k forks source link

go/parser: composite lit fields resolve incorrectly #45160

Open findleyr opened 3 years ago

findleyr commented 3 years ago

Resolving struct fields is a known limitation of go/parser object resolution. However, there is an additional bug that composite lit fields may be incorrectly resolved to unrelated declarations in the package scope. For example:

func _() {
  var tests = []dirLinkTest {
    {
      mklink: func(link, target string) error { return nil },
    },
  }
}

func mklink() {}

The mklink field identifier will be incorrectly resolved to the mklink function (found in os/os_windows_test.go).

Upon investigating this bug, it seems that it is a known limitation: https://cs.opensource.google/go/go/+/master:src/go/parser/parser.go;l=1610;drc=0bd308ff27822378dc2db77d6dd0ad3c15ed2e08

Will be fixed as part of #45104.

CC @griesemer

gopherbot commented 3 years ago

Change https://golang.org/cl/304450 mentions this issue: go/parser: add data-driven tests for object resolution

gopherbot commented 2 years ago

Change https://go.dev/cl/432137 mentions this issue: go/analysis/passes/loopclosure: use object resoluttion from go/types