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: found illegal assignment #50912

Closed
fgm opened this issue Jan 30, 2022 · 6 comments
Closed

cmd/compile: found illegal assignment #50912

fgm opened this issue Jan 30, 2022 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@fgm
Copy link

fgm commented Jan 30, 2022

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

$ gotip version
go version devel go1.18-a5c0b190 Sun Jan 30 02:29:51 2022 +0000 darwin/amd64

Does this issue reproduce with the latest release?

This is tip already

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

go env Output
$ gotip env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/fgm/Library/Caches/go-build"
GOENV="/Users/fgm/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/fgm/src/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/fgm/src/go"
GOPRIVATE=""
GOPROXY="http://localhost:3000|https://proxy.golang.org|direct"
GOROOT="/Users/fgm/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/fgm/sdk/gotip/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-a5c0b190 Sun Jan 30 02:29:51 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/fgm/src/go/src/code.osinet.fr/fgm/go__course/src/generics/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0g/p780bc554njc4qj110_8rmbr0000gn/T/go-build4100249988=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://gotipplay.golang.org/p/hdcd8wSANJ4

What did you expect to see?

No error, no display.

What did you see instead?

gotip run bug.go
# command-line-arguments
./bug.go:6:11: internal compiler error: found illegal assignment float32 -> main.Real.;

goroutine 1 [running]:
runtime/debug.Stack()
        /Users/fgm/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x0?, 0x0?}, {0x1938b25, 0x27}, {0xc00042cd18, 0x3, 0x3})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/noder.assignconvfn({0x1a95480, 0xc00041fea0}, 0xc0003e9490)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/transform.go:482 +0x1b2
cmd/compile/internal/noder.transformAssign({0x1a92a50?, 0xc00041fe50?}, {0xc00042d058, 0x1, 0x18?}, {0xc00042d048, 0x1, 0x1016ff3?})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/transform.go:428 +0xb5d
cmd/compile/internal/noder.(*subster).node.func1({0x1a92a50, 0xc00041ec80?})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:999 +0x745
cmd/compile/internal/noder.(*subster).node(0xc0003e9b20, {0x1a92a50, 0xc00041ec80})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1190 +0xa5
cmd/compile/internal/noder.(*subster).list(0xc00000e660?, {0xc0004165c0, 0x2, 0xc0000785a0?})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1462 +0x8e
cmd/compile/internal/noder.(*genInst).genericSubst(0x1f93aa0, 0xc00041fc70, 0xc00042e1a0, {0xc000061200, 0x2, 0x2}, {0xc000061210, 0x2, 0x2}, 0x0, ...)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:808 +0xc06
cmd/compile/internal/noder.(*genInst).getInstantiation(0x1f93aa0, 0xc00042e1a0, {0xc0000611f0, 0x2, 0x255ffff?}, 0x0)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:699 +0x53c
cmd/compile/internal/noder.(*genInst).scanForGenCalls.func1({0x1a92e38, 0xc000174b40?})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:151 +0x2df
cmd/compile/internal/ir.Visit.func1({0x1a92e38, 0xc000174b40})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes(...)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*Func).doChildren(0x1a93798?, 0xc00000df98?)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x6e
cmd/compile/internal/ir.DoChildren(...)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a93798, 0xc00040d080})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0x1a93798, 0xc00040d080}, 0xc000424880)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*genInst).scanForGenCalls(0x1f93aa0, {0x1a93798, 0xc00040d080})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:133 +0x1f0
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1f93aa0)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:60 +0x69
cmd/compile/internal/noder.BuildInstantiations(...)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc00014e240, {0xc00000e458, 0x1, 0x203000?})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:331 +0x3d1
cmd/compile/internal/noder.check2({0xc00000e458, 0x1, 0x1})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e220, 0x1, 0x0?})
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x194c750)
        /Users/fgm/sdk/gotip/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
        /Users/fgm/sdk/gotip/src/cmd/compile/main.go:55 +0xdd
@ianlancetaylor
Copy link
Contributor

CC @randall77 @danscales

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 30, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Jan 30, 2022
@randall77 randall77 self-assigned this Jan 31, 2022
@randall77
Copy link
Contributor

r's type is one of these weird derived type parameters, generated in cmd/compile/internal/types2/builtins.go:applyTypeFunc. I don't think we're handing substitution of those correctly. The new derived type parameter isn't in the list of type parameters, so we don't substitute it during stenciling like we should.

@griesemer griesemer self-assigned this Jan 31, 2022
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 31, 2022
@griesemer
Copy link
Contributor

griesemer commented Jan 31, 2022

Per internal discussion we are going to disallow this for 1.18: while the type checker can handle this fine and the compiler fix is not hard, it's not clear what the go/types API repercussions are. See #50937.

@gopherbot
Copy link

Change https://golang.org/cl/382116 mentions this issue: go/types, types2: disallow real, imag, complex on type parameters

@griesemer
Copy link
Contributor

Work-around real64 if one needs to use the built-in function real on a type parameter type:

func real64(x any) float64 {
	switch z := x.(type) {
	case complex64:
		return float64(real(z))
	case complex128:
		return real(z)
	default:
		panic("unknown complex type")
	}
}

Similarly for imag and complex.

@gopherbot
Copy link

Change https://golang.org/cl/381967 mentions this issue: doc/go1.18: document restrictions for real, imag, complex

gopherbot pushed a commit that referenced this issue Feb 1, 2022
For #47694.
For #50912.
For #50937.

Change-Id: I3fae6c8dbbd61a45e669b8fb0c18ac76f2183963
Reviewed-on: https://go-review.googlesource.com/c/go/+/381967
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@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.
Projects
None yet
Development

No branches or pull requests

5 participants