Skip to content

x/tools/gopls: failed assertion in go/types.validType0 #78042

Description

@adonovan
#!stacks
"types.assert" && "validType0:+92"

Issue created by stacks.

func (check *Checker) validType0(pos token.Pos, typ Type, nest, path []*Named) bool {
...	switch t := typ.(type) {
	case *Named:
...		// If the current type t is also found in nest, (the memory of) t is
		// embedded in itself, indicating an invalid recursive type.
		for _, e := range nest {
			if Identical(e, t) {
				// We have a cycle. If t != t.Origin() then t is an instance of
				// the generic type t.Origin(). Because t is in the nest, t must
				// occur within the definition (RHS) of the generic type t.Origin(),
				// directly or indirectly, after expansion of the RHS.
				// Therefore t.Origin() must be invalid, no matter how it is
				// instantiated since the instantiation t of t.Origin() happens
				// inside t.Origin()'s RHS and thus is always the same and always
				// present.
				// Therefore we can mark the underlying of both t and t.Origin()
				// as invalid. If t is not an instance of a generic type, t and
				// t.Origin() are the same.
				// Furthermore, because we check all types in a package for validity
				// before type checking is complete, any exported type that is invalid
				// will have an invalid underlying type and we can't reach here with
				// such a type (invalid types are excluded above).
				// Thus, if we reach here with a type t, both t and t.Origin() (if
				// different in the first place) must be from the current package;
				// they cannot have been imported.
				// Therefore it is safe to change their underlying types; there is
				// no chance for a race condition (the types of the current package
				// are not yet available to other goroutines).
				assert(t.obj.pkg == check.pkg)                       // FAIL
				assert(t.Origin().obj.pkg == check.pkg)

This stack mQWoXg was reported by telemetry:

golang.org/x/tools/gopls@v0.21.1 go1.26.0 windows/amd64 gopls.client=vscode (2)

Use this command to reproduce the executable:
(HOME=$(mktemp -d); GOOS=windows GOARCH=amd64 GOTOOLCHAIN=go1.26.0 go install golang.org/x/tools/gopls@v0.21.1 && find $HOME/go/bin -type f)
To disassemble: go tool objdump exe | less

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.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.gopls/telemetry-wins

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions