Skip to content

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

@mateusz834

Description

@mateusz834
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

Activity

mateusz834

mateusz834 commented on Jan 15, 2025

@mateusz834
MemberAuthor

This was found by a fuzzer.

findleyr

findleyr commented on Jan 15, 2025

@findleyr
Member

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

added this to the Go1.24 milestone on Jan 15, 2025
added
BugReportIssues describing a possible bug in the Go implementation.
on Jan 15, 2025
gopherbot

gopherbot commented on Jan 17, 2025

@gopherbot
Contributor

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

added a commit that references this issue on Jan 17, 2025
80bf7d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.release-blocker

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @griesemer@gopherbot@mateusz834@findleyr@gabyhelp

      Issue actions

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