Lyricdev
GitHub

LYR-MIG0322

an enum that holds itself

hint · spec 14-cli

A note of lyric fix --from-4: an enum holds itself, directly or through a struct. Lyric 4 kept payloads by reference; an enum of Lyric 5 is a value and would have no size.

Explanation

Lyric 5 refuses the type (LYR-SEM0056). A class in the cycle ends it, because a class is a reference.

One of the program's own keeps the matches readable, since a pattern can name its fields: Neg(Unary) with class Unary { x: Expr } and the pattern .Neg(Unary { x = .Lit(0) }). Box<T> of std.core needs no declaration, and its matches take the value out with .value. Either way the constructors and the patterns change, which is why this is by hand.

Example

by hand[LYR-MIG0322] main.lyr:1:1: the enum 'Expr' holds itself; an enum is a value in Lyric 5 and would have no size — put the recursive part behind a class: one of the program's own, whose fields a pattern can name, or 'Box<T>'