Open jgaskins opened 1 month ago
Yeah, this is essentially #2661.
As a workaround you can introduce a named type for Text | Image
, i.e. without Content
. In contrast to an unnamed union this won't be unified then.
abstract struct Content
end
abstract struct TextOrImageContent < Content
end
record Text < TextOrImageContent
record Image < TextOrImageContent
record Result < Content, content : Text | Image
As you can see, the union Text | Image
even works when there's a closer type that it can unify as.
Well, it's still unified, but we introduced an intermediary type to unify to (TextOrImageContent+
), instead of the top one (Content+
) :)
The compiler thinks it detects a recursive struct with this code:
The
Result
type can't hold an instance of itself, though, even via cyclical recursion. It is intended to be able to hold an instance of one of the other types, but since they can't hold aResult
(and nothing else in this code can, for that matter), there's no way for this to actually be a recursive struct.The recursive struct detection appears to be over-extrapolating from the
Text | Image
union type to allContent
subtypes.