Skip to content

go/parser: composite lit fields resolve incorrectly #45160

Open

Description

@findleyr

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

Activity

  1. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Mar 22, 2021
  2. added this to the Backlog milestone on Mar 22, 2021
  3. self-assigned this
    on Mar 22, 2021
  4. gopherbot commented on Mar 24, 2021

    @gopherbot
    Contributor

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

  5. gopherbot commented on Sep 20, 2022

    @gopherbot
    Contributor

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

  6. added
    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)
    on Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions