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: internal compiler error: found illegal assignment PTR-*Foo.T -> bang.Foo.U; #50147

mcy opened this issue Dec 13, 2021 · 6 comments
NeedsFix release-blocker


Copy link

@mcy mcy commented Dec 13, 2021

What version of Go are you using (go version)?

compile version devel go1.18-088bb4b Tue Nov 2 06:25:39 2021 +0000

Does this issue reproduce with the latest release?

This issue is only reproducible at head.

What operating system and processor architecture are you using (go env)?


What did you do?

package bang

func Foo[T any, U interface{~*T}](x T) {
  var _ U = &x

What did you expect to see?

Some kind of compilation error specifying that a conversion was not permitted.

What did you see instead?


./example.go:4:14: internal compiler error: found illegal assignment PTR-*Foo.T -> bang.Foo.U; 

goroutine 1 [running]:
	/root/master/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x0?, 0x0?}, {0xd262b1, 0x27}, {0xc0000c4fb8, 0x3, 0x3})
	/root/master/go/src/cmd/compile/internal/base/print.go:227 +0x1ca
cmd/compile/internal/noder.assignconvfn({0xe7d130, 0xc0003be190}, 0xc000396af0)
	/root/master/go/src/cmd/compile/internal/noder/transform.go:423 +0x1b2
cmd/compile/internal/noder.transformAssign({0xe7d450?, 0xc0003be1e0?}, {0xc0000c5200?, 0x1, 0x8?}, {0xc0000c51f0, 0x1, 0xc0000c51f0?})
	/root/master/go/src/cmd/compile/internal/noder/transform.go:369 +0x4b3
	/root/master/go/src/cmd/compile/internal/noder/decl.go:284 +0x5c5
cmd/compile/internal/noder.(*irgen).varDecl(0xc0000d4300, 0xc0000b3ae8, 0xc000087b60)
	/root/master/go/src/cmd/compile/internal/noder/decl.go:304 +0x331
cmd/compile/internal/noder.(*irgen).decls(0x1?, 0x0?, {0xc000080bc0?, 0x1, 0x0?})
	/root/master/go/src/cmd/compile/internal/noder/decl.go:34 +0xfd
cmd/compile/internal/noder.(*irgen).stmt(0xc0000d4300, {0xe7a960?, 0xc000385080?})
	/root/master/go/src/cmd/compile/internal/noder/stmt.go:50 +0x136
cmd/compile/internal/noder.(*irgen).stmts(0xc000396cb0?, {0xc000080bd0?, 0x1, 0x0?})
	/root/master/go/src/cmd/compile/internal/noder/stmt.go:19 +0xaf
cmd/compile/internal/noder.(*irgen).funcBody(0xc0000d4300, 0xc0003bcdc0, 0xb45c80?, 0xc0000b3780, 0xc0000b37c0)
	/root/master/go/src/cmd/compile/internal/noder/func.go:45 +0x25f
	/root/master/go/src/cmd/compile/internal/noder/decl.go:143 +0xf5
cmd/compile/internal/noder.(*irgen).generate(0xc0000d4300, {0xc0000b0458, 0x1, 0x203000?})
	/root/master/go/src/cmd/compile/internal/noder/irgen.go:280 +0x227
cmd/compile/internal/noder.check2({0xc0000b0458, 0x1, 0x1})
	/root/master/go/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc0000b4100, 0x1, 0x0?})
	/root/master/go/src/cmd/compile/internal/noder/noder.go:90 +0x335
	/root/master/go/src/cmd/compile/internal/gc/main.go:191 +0xb13
	/root/master/go/src/cmd/compile/main.go:55 +0xdd

Compiler returned: 2
@cherrymui cherrymui changed the title generics: internal compiler error: found illegal assignment PTR-*Foo.T -> bang.Foo.U; cmd/compile: internal compiler error: found illegal assignment PTR-*Foo.T -> bang.Foo.U; Dec 13, 2021
Copy link

@cherrymui cherrymui commented Dec 13, 2021

cc @griesemer @danscales @mdempsky

Copy link

@griesemer griesemer commented Dec 13, 2021

Simpler reproducer:

func _[P ~*int](x int) {
	var _ P = &x

This works:

func _[P ~*int](x int) {
	var _ P = P(&x)

@griesemer griesemer self-assigned this Dec 13, 2021
@griesemer griesemer added the NeedsFix label Dec 13, 2021
@griesemer griesemer added this to the Go1.18 milestone Dec 13, 2021
Copy link

@mdempsky mdempsky commented Dec 13, 2021

FWIW, the test cases work with GOEXPERIMENT=unified, so I don't think it's a types2 issue.

Copy link

@griesemer griesemer commented Dec 13, 2021

Agreed. They type-check fine and I believe the examples are valid.

Copy link

@danscales danscales commented Dec 14, 2021

This is related to the structural type constraint. It is why we need to do all the transformations on instantiations, rather than generic functions, so the structural constraints will be available to the compiler from the shape arguments supplied. But I missed delaying assignment transformations in varDecl(). Fix out shortly.

I'll include Robert (as well as Keith) on the reviewers to decide if the fix should go in for beta1. It's a fairly simple fix, but it is last minute...

Copy link

@gopherbot gopherbot commented Dec 14, 2021

Change mentions this issue: cmd/compile: fix case where we didn't delay transformAssign in varDecl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
NeedsFix release-blocker
None yet

No branches or pull requests

6 participants