Navigation Menu

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

Closed
mcy opened this issue Dec 13, 2021 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@mcy
Copy link

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)?

GOHOSTARCH="amd64"
GOHOSTOS="linux"

What did you do?

package bang

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

https://godbolt.org/z/GocK9493c

What did you expect to see?

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

What did you see instead?

ICE:

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

goroutine 1 [running]:
runtime/debug.Stack()
	/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/base.Fatalf(...)
	/root/master/go/src/cmd/compile/internal/base/print.go:196
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
cmd/compile/internal/noder.(*irgen).varDecl.func1()
	/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
cmd/compile/internal/noder.(*irgen).funcDecl.func1()
	/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
cmd/compile/internal/gc.Main(0xd3a138)
	/root/master/go/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
	/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
@cherrymui
Copy link
Member

cc @griesemer @danscales @mdempsky

@griesemer
Copy link
Contributor

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 The path to resolution is known, but the work has not been done. label Dec 13, 2021
@griesemer griesemer added this to the Go1.18 milestone Dec 13, 2021
@mdempsky
Copy link
Member

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

@griesemer
Copy link
Contributor

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

@danscales
Copy link
Contributor

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...

@gopherbot
Copy link

Change https://golang.org/cl/371534 mentions this issue: cmd/compile: fix case where we didn't delay transformAssign in varDecl

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

6 participants