Skip to content

x/tools/gopls: "expected exported symbol" assert in getOneTransitiveRefLocked #71356

@adonovan

Description

@adonovan
#!stacks
"cache.assert" && "evaluatePackageHandle.func1:+2"

Issue created by stacks.

// getOneTransitiveRefLocked computes the full set packages transitively
// reachable through the given sym reference.
//
// It may return nil if the reference is invalid (i.e. the referenced name does
// not exist).
func (b *packageHandleBuilder) getOneTransitiveRefLocked(sym typerefs.Symbol) *typerefs.PackageSet {
	assert(token.IsExported(sym.Name), "expected exported symbol")  <--- here

	trefs := b.transitiveRefs[sym.Package]
	if trefs == nil {
		trefs = &partialRefs{
			refs:     make(map[string]*typerefs.PackageSet),
			complete: false,
		}
		b.transitiveRefs[sym.Package] = trefs
	}

This stack N2fS6w was reported by telemetry:

golang.org/x/tools/gopls@v0.17.0 go1.23.4 linux/amd64 vscode (1)

Activity

added
goplsIssues related to the Go language server, gopls.
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Jan 20, 2025
added this to the Unreleased milestone on Jan 20, 2025
adonovan

adonovan commented on Jan 20, 2025

@adonovan
MemberAuthor

What we know:

  • sym.Name is non-exported.
  • sym comes from a value in the node.ph.refs map.
  • the refs map is set by evaluatePackageHandle to the result of Snapshot.typerefs()
  • its values from the Refs field of the result of typerefs.Decode.
  • assuming the encode/decode pair is lossless, this value must have come from typesrefs.state.class, which is inserted by state.getClassIndex.
  • this value comes from typestate.declNode.extRefs.
  • extRefs is inserted in three places, two of which are unions (inductive case); the third (base case) is the importEdge lambda in typerefs.visitFile, which is dominated a token.IsExported check.

So, this can't happen (modulo: bugs in encode/decode pair, compiler, runtime, hardware). What am I missing?

self-assigned this
on Jan 21, 2025
added
gopls/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)
on Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)gopls/telemetry-wins

Type

No type

Projects

No projects

Development

No branches or pull requests

    Participants

    @adonovan@gopherbot@findleyr

    Issue actions

      x/tools/gopls: "expected exported symbol" assert in getOneTransitiveRefLocked · Issue #71356 · golang/go