3eb1ad3a82
Sessions 18–23 quality work: - B.3c match arm guards + sequential found-flag lower (bootstrap + selfhost) - Generic HOF type inference (Array/Iter map/filter/fold without type args) - Pattern binding shadowing via unique C locals (__pN_src) - Ownership C.2 exclusive &mut data-flow + C.4 goldens; *p= store-through fix - Ownership C.3 auto-drop on early return/branches: scoped defers, move-on-return, Drop monomorphization, materialize return before Drop - LSP 0.3.0: hover from real sema types - Examples and QUALITY_PLAN session log; selfhost-loop identical
51 lines
1.2 KiB
Plaintext
51 lines
1.2 KiB
Plaintext
import Std::Test::{Test_AssertEqInt, Test_Pass};
|
|
import Std::Io::{PrintInt, PrintLine};
|
|
|
|
enum Option {
|
|
Some(int),
|
|
None
|
|
}
|
|
|
|
func Main() -> int {
|
|
let a: Option = Option { tag: Option_Some };
|
|
a.data.Some_0 = 10;
|
|
let b: Option = Option { tag: Option_Some };
|
|
b.data.Some_0 = 20;
|
|
|
|
// Same binding name `v` in two sequential matches
|
|
let x: int = match a {
|
|
Option::Some(v) => v + 1,
|
|
Option::None => 0
|
|
};
|
|
let y: int = match b {
|
|
Option::Some(v) => v + 2,
|
|
Option::None => 0
|
|
};
|
|
Test_AssertEqInt(x, 11);
|
|
Test_AssertEqInt(y, 22);
|
|
|
|
// Nested: outer and inner both bind `n`
|
|
let nested: int = match a {
|
|
Option::Some(n) => match b {
|
|
Option::Some(n) => n, // should be b's payload (20), not a's
|
|
Option::None => -1
|
|
},
|
|
Option::None => -2
|
|
};
|
|
Test_AssertEqInt(nested, 20);
|
|
|
|
// Shadow outer let with pattern binding
|
|
let v: int = 99;
|
|
let z: int = match a {
|
|
Option::Some(v) => v, // pattern v should be 10, not 99
|
|
Option::None => 0
|
|
};
|
|
Test_AssertEqInt(z, 10);
|
|
Test_AssertEqInt(v, 99); // outer v unchanged
|
|
|
|
PrintInt(nested);
|
|
PrintLine("");
|
|
Test_Pass("pat_shadow");
|
|
return 0;
|
|
}
|