Files
bux-lang/examples/borrow.bux
T
dimgigov 53b43b0f79 feat: lifetime elision, tooling CI, registry, and LSP locals
Ship the QUALITY_PLAN stretch from ownership through ecosystem: C.1
lifetime elision (bootstrap + selfhost), bux fmt/test/doc CI hooks,
stdlib goldens, package registry (bux search/add), and LSP 0.4
position-sensitive locals with inferred let types. Full-tree format
pass plus Map/Set remove double-free fix.
2026-07-19 16:35:08 +03:00

34 lines
648 B
Plaintext

// borrow.bux — Test explicit borrow expressions
struct Point {
x: int;
y: int;
}
// NOT @[Checked] — borrow keyword available everywhere
func MovePoint(p: *Point) {
let ref: &Point = borrow &p;
let x: int = (*ref).x;
}
// @[Checked] enables borrow protection
@[Checked]
func SwapPoints(a: *Point, b: *Point) {
let ra: &mut Point = borrow &mut a;
let rb: &mut Point = borrow &mut b;
let tmp: int = (*ra).x;
(*ra).x = (*rb).x;
(*rb).x = tmp;
}
func Main() -> int {
var p1: Point;
p1.x = 10;
p1.y = 20;
var p2: Point;
p2.x = 30;
p2.y = 40;
SwapPoints(&p1, &p2);
return 0;
}