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 FUNC-func() T₁ -> main.T₁; #48137

Closed
reusee opened this issue Sep 2, 2021 · 2 comments
Assignees
Milestone

Comments

@reusee
Copy link

@reusee reusee commented Sep 2, 2021

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

$ go version
go version devel go1.18-df4c625d88 Thu Sep 2 01:06:17 2021 +0000 windows/amd64

Does this issue reproduce with the latest release?

No

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\reus\AppData\Local\go-build
set GOENV=C:\Users\reus\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\reus\go\pkg\mod
set GONOPROXY=github.com/reusee/*
set GONOSUMDB=github.com/reusee/*
set GOOS=windows
set GOPATH=C:\Users\reus\go
set GOPRIVATE=github.com/reusee/*
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Users\reus\gotip
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\reus\gotip\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.18-df4c625d88 Thu Sep 2 01:06:17 2021 +0000
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\reus\AppData\Local\Temp\go-build4127425866=/tmp/go-build -gno-record-gcc-switches
GOROOT/bin/go version: go version devel go1.18-df4c625d88 Thu Sep 2 01:06:17 2021 +0000 windows/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.18-df4c625d88 Thu Sep 2 01:06:17 2021 +0000

What did you do?

package main

func Foo[
        T interface {
                ~func() T
        },
]() T {
        var t T
        t = func() T {
                return t
        }
        return t
}

func main() {
  type Bar func() Bar
  Foo[Bar]()
}

What did you expect to see?

Compile OK

What did you see instead?

# command-line-arguments
.\a.go:9:2: internal compiler error: found illegal assignment FUNC-func() T₁ -> main.T₁;

goroutine 1 [running]:
runtime/debug.Stack()
        C:/Users/reus/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x0, 0x0}, {0x144f237, 0x27}, {0xc0000cd250, 0x3, 0x3})
        C:/Users/reus/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
        C:/Users/reus/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/noder.assignconvfn({0x15adc90, 0xc00007a5f0}, 0xc000404620)
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/transform.go:413 +0x165
cmd/compile/internal/noder.transformAssign({0x15ad650, 0xc00007a730}, {0xc0000cd538, 0x1, 0x38}, {0xc0000cd528, 0x1, 0x1b3b503352f})
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/transform.go:363 +0x4b3
cmd/compile/internal/noder.(*irgen).stmt(0xc000410000, {0x15991b8, 0xc0000761c0})
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/stmt.go:109 +0xfbe
cmd/compile/internal/noder.(*irgen).stmts(0xc0004049a0, {0xc000076200, 0x3, 0xc0000061d0})
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/stmt.go:19 +0xaf
cmd/compile/internal/noder.(*irgen).funcBody(0xc000410000, 0xc00007e2c0, 0x12c8bfd, 0xc0000760c0, 0xc000076100)
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/func.go:45 +0x25f
cmd/compile/internal/noder.(*irgen).funcDecl.func1()
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/decl.go:128 +0x68
cmd/compile/internal/noder.(*irgen).generate(0xc000410000, {0xc000088b50, 0x2, 0x1b197c0})
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/irgen.go:265 +0x1df
cmd/compile/internal/noder.check2({0xc000088b50, 0x2, 0x2})
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x175
cmd/compile/internal/noder.LoadPackage({0xc0000de100, 0x2, 0x0})
        C:/Users/reus/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x1462ac8)
        C:/Users/reus/gotip/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        C:/Users/reus/gotip/src/cmd/compile/main.go:55 +0xdd


Compile OK in unified mode.

@ALTree ALTree added this to the Go1.18 milestone Sep 2, 2021
@danscales danscales self-assigned this Sep 2, 2021
@danscales
Copy link

@danscales danscales commented Sep 2, 2021

A slightly different form, that may be more readable:

package main

type Constraint[T any] interface {
	~func() T
}

func Foo[T Constraint[T]]() T {
	var t T

	t = func() T {
		return t
	}
	return t
}

func main() {
	type Bar func() Bar
	Foo[Bar]()
}

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 7, 2021

Change https://golang.org/cl/347915 mentions this issue: cmd/compile: delay transformAssign if lhs/rhs have typeparam

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

Successfully merging a pull request may close this issue.

None yet
4 participants