Repository navigation
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.okay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1release-blocker
Milestone
Description
What version of Go are you using (go version)?
$ go version go version go1.18beta1 linux/amd64
Does this issue reproduce with the latest release?
Yes, assuming the latest version is gotip.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/dev/.cache/go-build" GOENV="/home/dev/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/dev/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/dev/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/dev/sdk/go1.18beta1" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/dev/sdk/go1.18beta1/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18beta1" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/workspace/dev/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build929647144=/tmp/go-build -gno-record-gcc-switches"
What did you do?
This came up as I was trying to write some table driven unit tests for some functions that allow for generics. I've reduced the problem to this:
https://gotipplay.golang.org/p/0FYmUq0bzvr
The issue appears only if the a type is declared with the same name within multiple functions of a package file, and there is a field on the types with the same name, but different signature.
If I rename one of the types in the caller* functions, I do not see the issue.
What did you expect to see?
Compiled code.
What did you see instead?
# command-line-arguments ./issue.go:22:14: internal compiler error: found illegal assignment FUNC-func(int) error -> main.Fn[int]; Please file a bug report including a short program that triggers the error. https://golang.org/issue/new
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.okay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1release-blocker
Activity
ianlancetaylor commentedon Dec 15, 2021
Thanks. Can you please include a short program that triggers the error?
[-]affected/package: [/-][+]cmd/compile: found illegal assignment FUNC-func(int) error -> main.Fn[int]; [/+]gus commentedon Dec 15, 2021
Sorry, accidentally hit
tab+enterprematurely. Issue updated with more details.ianlancetaylor commentedon Dec 15, 2021
CC @danscales @randall77
(Compilation succeeds with
GOEXPERIMENT=unified)randall77 commentedon Dec 15, 2021
I don't think this will work currently. We don't allow local type declarations (or functions for that matter) with generic parameters.
Or at least, we shouldn't. Definitely needs a better error message.
Somewhat related to #47631 except it's a generic type declaration in a non-generic function, instead of a non-generic type declaration in a generic function.
gus commentedon Dec 15, 2021
Thanks, @randall77 . More than happy to be told not to do this as I didn't really like the way the test was looking anyway; but
goplswasn't complaining, so I forged ahead. I will add that if the signature forfnin bothXtypes is the same, then the code compiles (and works if you add amainfunction to the example).randall77 commentedon Dec 15, 2021
@gri @ianlancetaylor @findleyr @danscales
I guess we need to decide whether we support local declarations of generic types in non-generic functions. Maybe we could? I'm not sure if this doesn't work because we never tried it, or because it's not supposed to work, or because it should work but doesn't. Opinions welcome.
I have a CL ready to officially make this an error like for #47631, but that's only if we decide it is the right thing to do.
gopherbot commentedon Dec 15, 2021
Change https://golang.org/cl/372154 mentions this issue:
cmd/compile: don't allow generic type declarations inside functionsdanscales commentedon Dec 15, 2021
It looks like we are confusing the two local named types X incorrectly. If you rename the second local type to Y, things work fine. We don't have the same confusion for non-generic local types, so must be some generic-only state. I will take a further look.
However, I would say, for this release, it is probably less confusing to the user and reduces the number of possible unusual cases if we disallow local generic type declarations in non-generic functions.
ianlancetaylor commentedon Dec 15, 2021
I think that eventually we should support local declarations of generic types in non-generic functions, but I think it's fine if we don't support that in 1.18.
gopherbot commentedon Dec 16, 2021
Change https://golang.org/cl/372654 mentions this issue:
cmd/compile: pop instantiations of local types when leaving scopedanscales commentedon Dec 16, 2021
The problem is that instantiations of local types need to be popped from the symbol table when leaving the scope of the local type, else they might get used for an instantiation of a later same-name local type. I have the relatively simple fix above, but still need to think about other possible issues, since local generic types was not a focus for the code and we have no tests.
cmd/compile: pop instantiations of local types when leaving scope
cmd/compile: pop instantiations of local types when leaving scope