Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types: failed genericType assertion in Checker.instantiatedType #71198

Open
adonovan opened this issue Jan 9, 2025 · 6 comments
Open

go/types: failed genericType assertion in Checker.instantiatedType #71198

adonovan opened this issue Jan 9, 2025 · 6 comments
Assignees
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. release-blocker Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Jan 9, 2025

#!stacks
"runtime.typeAssert" && "go/types.(*Checker).instantiatedType:+38"

Issue created by stacks.

func (check *Checker) instantiatedType(ix *indexedExpr, def *TypeName) (res Type) {
...
	// create instance
	// The instance is not generic anymore as it has type arguments, but it still
	// satisfies the genericType interface because it has type parameters, too.
	inst := check.instance(ix.Pos(), gtyp, targs, nil, check.context()).(genericType)

This stack aEVlDg was reported by telemetry:

golang.org/x/tools/[email protected] go1.24rc1 linux/amd64 vscode (10)

cc: @griesemer @findleyr

Dups: HNc-0g sRb2ZQ caAKMA ubM70w f0cr5w -B6Zow

@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels Jan 9, 2025
@adonovan
Copy link
Member Author

adonovan commented Jan 9, 2025

This stack HNc-0g was reported by telemetry:

golang.org/x/tools/[email protected] go1.24rc1 linux/amd64 vscode (5)

This stack sRb2ZQ was reported by telemetry:

golang.org/x/tools/[email protected] go1.24rc1 linux/amd64 vscode (13)

This stack caAKMA was reported by telemetry:

golang.org/x/tools/[email protected] go1.24rc1 linux/amd64 vscode (2)

This stack ubM70w was reported by telemetry:

golang.org/x/tools/[email protected] go1.24rc1 linux/amd64 vscode (5)

This stack f0cr5w was reported by telemetry:

golang.org/x/tools/[email protected] go1.24rc1 linux/amd64 vscode (19)

This stack -B6Zow was reported by telemetry:

golang.org/x/tools/[email protected] go1.24rc1 linux/amd64 vscode (42)

@findleyr
Copy link
Member

findleyr commented Jan 9, 2025

The bug is that Checker.instance can return a Typ[Invalid], which is not a generic type.

All crashes are with the rc1, indicating that this is a regression. Marking as a release blocker.

CC @griesemer

@findleyr findleyr added this to the Go1.24 milestone Jan 9, 2025
@findleyr
Copy link
Member

findleyr commented Jan 9, 2025

Repro: https://go.dev/play/p/77Rx2onG7rT?v=gotip

package main

import (
	"go/ast"
	"go/parser"
	"go/token"
	"go/types"
)

const src = `
package p

type I[T any] = interface {
}

func F[T I[int, string]]() {
}
`

func main() {
	fset := token.NewFileSet()
	f, _ := parser.ParseFile(fset, "p.go", src, 0)
	conf := types.Config{Error: func(error) {}}
	conf.Check("p", fset, []*ast.File{f}, nil)
}

@griesemer
Copy link
Contributor

I will take this one on. Thanks for reporting.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/641857 mentions this issue: go/types, types2: don't panic when instantiating generic alias with wrong number of type arguments

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 9, 2025
@griesemer griesemer moved this to All-But-Submitted in Go Compiler / Runtime Jan 9, 2025
@griesemer griesemer moved this from All-But-Submitted to In Progress in Go Compiler / Runtime Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. release-blocker Tools This label describes issues relating to any tools in the x/tools repository.
Projects
Status: In Progress
Development

No branches or pull requests

5 participants