Skip to content

x/tools/gopls: race in ad-hoc package reloading can lead to conflicting diagnostics #57209

Closed
@findleyr

Description

@findleyr

Gopls has some support for ad-hoc packages, which are packages defined in a directory outside of a module or GOPATH. To support them, it sets GO111MODULE=auto and loads .. However, I observe that gopls also load individual files eagerly, and this can lead to conflicting state.

Consider the following simple ad-hoc package:

-- a.go --
package foo

const X = 1

-- b.go --
package foo

const Y = X

If I trigger repeated reloads of b.go (for example, by typing in an import statement in b.go), I can sometimes trigger a state where I can an "undefined name: X" diagnostics even though cross references on X work. The reason for this, I assume, is that we eagerly load file:b.go before reloading the directory ., resulting in multiple packages containing b.go, one of which does not contain a.go.

CC @adonovan

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions