Description
The following code
package p
var x T[B]
type T[_ any] struct{}
type A T[B /* ERROR invalid use of type alias */ ]
type B = T[A]
reports an error when we use B
in a recursive type definition due to the way type aliases are handled inside the type checker. In this (and possibly many other similar) cases, the error can be avoided by restructuring the code slightly. This version compiles without error (declaration of x
moved past the type declarations):
package p
type T[_ any] struct{}
type A T[B]
type B = T[A]
var x T[B]
The compiler should be able to avoid this error on its own.
Root cause: Currently, the type checker doesn't have a "forwarding mechanism" for type aliases that are being "used" before their respective type is fully known. To solve this problem in general, a forwarding mechanism/type needs to be introduced. This is only an issue with some recursive type definitions involving type aliases.
cc: @findleyr
Metadata
Metadata
Assignees
Labels
Type
Projects
Status