Owner rules: struct/enum declarations in Rust form; one construction form each (named struct literal, Enum::Variant); struct fields lowered in declaration order, so field order in the source does not change the AIR (golden test with two orders, one AIR); match over enums exhaustive with no '_' (E7004 lists missing variants, E7006 for '_'), integer match needs '_'; payload names scoped to their arm (enum.switch block parameters); match as an expression with a merge block; arm-level source map; no destructuring, guards or nested patterns. Type inference limits written into spec 15 (one function, monomorphic, no search, E7007). aji lower --stats: source/AIR size and expansion ratio. Tests: 4 run (one shared golden), 7 rejects incl. verifier-caught E1003.
30 lines
590 B
Rust
30 lines
590 B
Rust
// Enum construction with Enum::Variant, exhaustive match as an expression, payloads scoped to their arm.
|
|
// expect: run
|
|
// result: 42
|
|
// phase: 6
|
|
// spec: docs/spec/15-source-language.md
|
|
module demo.messages
|
|
|
|
enum Message {
|
|
Stop,
|
|
Value(u64),
|
|
Pair(u64, u64),
|
|
}
|
|
|
|
fn weight(m: Message) -> u64
|
|
effects []
|
|
{
|
|
let w: u64 = match m {
|
|
Message::Stop => 0,
|
|
Message::Value(x) => x,
|
|
Message::Pair(a, b) => a * b,
|
|
};
|
|
return w;
|
|
}
|
|
|
|
fn main() -> u64
|
|
effects []
|
|
{
|
|
return weight(Message::Stop) + weight(Message::Value(12)) + weight(Message::Pair(5, 6));
|
|
}
|