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

cmd/compile: "panic: assertion failed" when compiling illegal code #47883

Closed
4ad opened this issue Aug 22, 2021 · 2 comments
Closed

cmd/compile: "panic: assertion failed" when compiling illegal code #47883

4ad opened this issue Aug 22, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@4ad
Copy link
Member

@4ad 4ad commented Aug 22, 2021

On tip (6e50991):

Repro:

package p

type Foo[t any] interface {
	Bar(Bar[t])
}
type Bar[t any] interface {
	Foo
}
go build k.go
# command-line-arguments
panic: assertion failed [recovered]
	panic: assertion failed

goroutine 1 [running]:
cmd/compile/internal/types2.(*Checker).handleBailout(0xc0000f4640, 0xc0000cd690)
	/Users/aram/go/src/cmd/compile/internal/types2/check.go:240 +0x8b
panic({0x185a220, 0x1a3b7d0})
	/Users/aram/go/src/runtime/panic.go:814 +0x214
cmd/compile/internal/types2.assert(...)
	/Users/aram/go/src/cmd/compile/internal/types2/errors.go:23
cmd/compile/internal/types2.(*subster).typ(0xc0000cd388, {0x1a49e10, 0xc0000c4a00})
	/Users/aram/go/src/cmd/compile/internal/types2/subst.go:191 +0x195a
cmd/compile/internal/types2.(*subster).typeList(0x3, {0xc000098bf0, 0x1, 0xc0000f4640})
	/Users/aram/go/src/cmd/compile/internal/types2/subst.go:370 +0xaa
cmd/compile/internal/types2.(*subster).typ(0xc0000cd388, {0x1a49dc0, 0xc0003b9c20})
	/Users/aram/go/src/cmd/compile/internal/types2/subst.go:153 +0xaa5
cmd/compile/internal/types2.(*Checker).subst(0xc0000b64b8, {0xc000372ed0, 0x1, 0x0}, {0x1a49dc0, 0xc0003b9c20}, 0xc0000cd418, 0x174d8d7)
	/Users/aram/go/src/cmd/compile/internal/types2/subst.go:77 +0x132
cmd/compile/internal/types2.(*Named).expand(0xc0000c4b40, 0x0)
	/Users/aram/go/src/cmd/compile/internal/types2/named.go:275 +0x185
cmd/compile/internal/types2.(*Named).Underlying(0x1)
	/Users/aram/go/src/cmd/compile/internal/types2/named.go:159 +0x25
cmd/compile/internal/types2.(*Named).under(0xc0000c4b40)
	/Users/aram/go/src/cmd/compile/internal/types2/named.go:172 +0x36
cmd/compile/internal/types2.(*Checker).newNamed.func1()
	/Users/aram/go/src/cmd/compile/internal/types2/named.go:101 +0x25
cmd/compile/internal/types2.(*Checker).processDelayed(0xc0000f4640, 0x0)
	/Users/aram/go/src/cmd/compile/internal/types2/check.go:307 +0x35
cmd/compile/internal/types2.(*Checker).checkFiles(0xc0000f4640, {0xc0000b6470, 0x0, 0x0})
	/Users/aram/go/src/cmd/compile/internal/types2/check.go:272 +0x2c8
cmd/compile/internal/types2.(*Checker).Files(...)
	/Users/aram/go/src/cmd/compile/internal/types2/check.go:245
cmd/compile/internal/noder.checkFiles({0xc0000b6430, 0x1, 0x203000})
	/Users/aram/go/src/cmd/compile/internal/noder/irgen.go:65 +0x43e
cmd/compile/internal/noder.check2({0xc0000b6430, 0x1, 0x1})
	/Users/aram/go/src/cmd/compile/internal/noder/irgen.go:78 +0x46
cmd/compile/internal/noder.LoadPackage({0xc0000be110, 0x1, 0x0})
	/Users/aram/go/src/cmd/compile/internal/noder/noder.go:90 +0x365
cmd/compile/internal/gc.Main(0x1918b50)
	/Users/aram/go/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
	/Users/aram/go/src/cmd/compile/main.go:55 +0xdd

Notice how Bar[t] mistakenly embeds Foo, not Foo[t]. The correct code works.

package p

type Foo[t any] interface {
	Bar(Bar[t])
}
type Bar[t any] interface {
	Foo[t]
}
@4ad 4ad added this to the Go1.18 milestone Aug 22, 2021
@griesemer griesemer self-assigned this Aug 25, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 26, 2021

Likely related to #47887.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Sep 15, 2021

This is now fixed, likely with the fix for #47887. Compiling the 1st example correctly reports:

x.go:7:2: cannot use generic type Foo[t interface{}] without instantiation

Loading

@griesemer griesemer closed this Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants