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: recursive type aliases might cause a panic #71284

Closed
mateusz834 opened this issue Jan 15, 2025 · 4 comments
Closed

go/types: recursive type aliases might cause a panic #71284

mateusz834 opened this issue Jan 15, 2025 · 4 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. release-blocker
Milestone

Comments

@mateusz834
Copy link
Member

Reproducer:

const src = `package A

type (
        A0 = A
        A  = A
)

`

func run() error {
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "test.go", src, parser.SkipObjectResolution)
	if err != nil {
		return err
	}
	_, err = (&types.Config{
		Error: func(err error) {},
	}).Check("test", fset, []*ast.File{f}, &types.Info{})
	return err
}
$ go run .
panic: t.fromRHS = test.A, typ = invalid type
         [recovered]
        panic: t.fromRHS = test.A, typ = invalid type


goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc000007500, 0xc00012be20)
        /usr/lib/go/src/go/types/check.go:404 +0x88
panic({0x584240?, 0xc000014210?})
        /usr/lib/go/src/runtime/panic.go:785 +0x132
go/types.setDefType(0xc000007500?, {0x5fbce0, 0x6f4720})
        /usr/lib/go/src/go/types/typexpr.go:422 +0x294
go/types.(*Checker).typInternal(0xc000007500, {0x5fbff8, 0xc0000780a0}, 0xc00010f3b0)
        /usr/lib/go/src/go/types/typexpr.go:267 +0x659
go/types.(*Checker).definedType(0xc000007500, {0x5fbff8, 0xc0000780a0}, 0x6f4720?)
        /usr/lib/go/src/go/types/typexpr.go:201 +0x2f
go/types.(*Checker).typeDecl(0xc000007500, 0xc00010f3b0, 0xc000100280, 0x0)
        /usr/lib/go/src/go/types/decl.go:610 +0x8cd
go/types.(*Checker).objDecl(0xc000007500, {0x5fe198, 0xc00010f3b0}, 0x0)
        /usr/lib/go/src/go/types/decl.go:191 +0xa3f
go/types.(*Checker).packageObjects(0xc000007500)
        /usr/lib/go/src/go/types/resolver.go:710 +0x408
go/types.(*Checker).checkFiles(0xc000007500, {0xc000106ef0, 0x1, 0x1})
        /usr/lib/go/src/go/types/check.go:459 +0x15a
go/types.(*Checker).Files(0x5b6095?, {0xc000106ef0?, 0xc0000326c0?, 0x0?})
        /usr/lib/go/src/go/types/check.go:422 +0x75
go/types.(*Config).Check(0xc00011c0e0, {0x5b6095?, 0x7?}, 0xc000100240, {0xc000106ef0, 0x1, 0x1}, 0xc000032600)
        /usr/lib/go/src/go/types/api.go:476 +0x79
main.run()
        /tmp/aa/main.go:32 +0xc5
main.main()
        /tmp/aa/main.go:12 +0x13
exit status 2

CC @adonovan @findleyr @griesemer

@mateusz834
Copy link
Member Author

This was found by a fuzzer.

@findleyr
Copy link
Member

Thank you. I believe this should also block the 1.24 release.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Jan 15, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/643255 mentions this issue: go/types, types2: remove superfluous assertion (fix build)

Clement-Jean pushed a commit to Clement-Jean/go that referenced this issue Jan 31, 2025
Remove an assertion that was overly restrictive and hard to get
correct under all circumstances (i.e., in the presence of incorrect)
code. This matches the code for *Named types in that specific switch.

Fixes golang#71284.

Change-Id: Ifccf8b73dc70cac9cb1c8b24946d16851d511454
Reviewed-on: https://go-review.googlesource.com/c/go/+/643255
Reviewed-by: Robert Findley <[email protected]>
Auto-Submit: Robert Griesemer <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@findleyr findleyr marked this as a duplicate of #71029 Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants