feat: multi-stmt match arms and block-as-expression
Blocks can yield a value: last expression statement is the result.
Match arms accept block bodies, so multi-statement arms work:
match n {
1 => { let a = 10; a + 1 },
_ => 0
}
Bootstrap: lowerBlock(asExpr) lifts the trailing skExpr. Selfhost: parse
{...} as ekBlock, emit __blk_N yield temps (retTypeKind -2), and treat
only non-empty strValue as match/block yield. Nested enum/struct pattern
bindings recurse in both compilers.
Example: match_block.bux. Selfhost-loop remains binary-identical.
This commit is contained in:
@@ -396,6 +396,21 @@ match p {
|
||||
Point { x, y } => x * 10 + y,
|
||||
_ => -1
|
||||
}
|
||||
|
||||
// Multi-statement arm bodies (block expression; last expr is the value)
|
||||
match n {
|
||||
1 => {
|
||||
let a: int = 10;
|
||||
a + 1
|
||||
},
|
||||
_ => 0
|
||||
}
|
||||
|
||||
// Block as expression
|
||||
let r: int = {
|
||||
let x: int = 5;
|
||||
x + 6
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user