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
36 lines
579 B
Plaintext
36 lines
579 B
Plaintext
import Std::Io::{PrintLine, PrintInt};
|
|
import Std::Test::{Test_AssertEqInt, Test_Pass};
|
|
|
|
func UncheckedInc(p: *int) {
|
|
*p = *p + 1;
|
|
}
|
|
|
|
@[Checked]
|
|
func Inc(p: &mut int) {
|
|
*p = *p + 1;
|
|
}
|
|
|
|
@[Checked]
|
|
func Get(p: &int) -> int {
|
|
return *p;
|
|
}
|
|
|
|
@[Checked]
|
|
func OkBorrow() -> int {
|
|
var x: int = 10;
|
|
Inc(&x);
|
|
return Get(&x);
|
|
}
|
|
|
|
func Main() -> int {
|
|
var n: int = 1;
|
|
UncheckedInc(&n);
|
|
Test_AssertEqInt(n, 2);
|
|
let r: int = OkBorrow();
|
|
Test_AssertEqInt(r, 11);
|
|
PrintInt(r);
|
|
PrintLine("");
|
|
Test_Pass("ownership_checked");
|
|
return 0;
|
|
}
|