-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: crash instantiating with recursive type #50259
Comments
CC @randall77 @danscales @griesemer @findleyr This is invalid code so not marking as a release blocker. It may be a bug that this is getting past the type checker. Here is a single file reproducer. package foo
var v Box[Step]
type Box[T any] struct{}
type Step = Box[StepBox]
type StepBox Box[Step] Running
|
Yes, I think this should not get past the type checker. |
Change https://golang.org/cl/379916 mentions this issue: |
Change https://golang.org/cl/380056 mentions this issue: |
By processing non-alias type declarations before alias type declaration, and those before everything else we can avoid some of the remaining errors which are due to alias types not being available. For #25838. For #50259. For #50276. For #50729. Change-Id: I233da2899a6d4954c239638624dfa8c08662e6b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/380056 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
The type checker doesn't have a general mechanism to "use" the type of a type alias whose type depends on a recursive type declaration which is not yet completely type-checked. In some cases, the type of a type alias is needed before it is determined; the type is incorrect (invalid) in that case but no error is reported. The type-checker is happy with this (incorrect type), but the compiler may crash under some circumstances. A correct fix will likely require some form of forwarding type which is a fairly pervasive change and may also affect the type checker API. This CL introduces a simple side table, a map of broken type aliases, which is consulted before the type associated with a type alias is used. If the type alias is broken, an error is reported. This is a stop-gap solution that prevents the compiler from crashing. The reported error refers to the corresponding issue which suggests a work-around that may be applicable in some cases. Also fix a minor error related to type cycles: If we have a cycle that doesn't start with a type, don't use a compiler error message that explicitly mentions "type". Fixes golang#50259. Fixes golang#50276. Fixes golang#50779. For golang#50729. Change-Id: Ie8e38f49ef724e742e8e78625e6d4f3d4014a52c Reviewed-on: https://go-review.googlesource.com/c/go/+/379916 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
By processing non-alias type declarations before alias type declaration, and those before everything else we can avoid some of the remaining errors which are due to alias types not being available. For golang#25838. For golang#50259. For golang#50276. For golang#50729. Change-Id: I233da2899a6d4954c239638624dfa8c08662e6b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/380056 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?Can reproduce in playground, but locally
What did you do?
I referred to a recursive type from another file, causing a recursive type error to turn into a compiler crash.
See https://go.dev/play/p/FMJLSwjhEMU?v=gotip
What did you expect to see?
Either a clean compile, or a clear warning that I'm breaking the type rules.
What did you see instead?
The text was updated successfully, but these errors were encountered: