Files
sakurac/tests/programs/boxes_and_containers_close_whole_values_1.sakura
T
2026-11-19 04:54:17 -06:00

23 lines
970 B
Plaintext

import std::io;
import lib;
struct leaf : owning { var n: int; }
def leaf::close(&mut this): void { if this.n != 0 { println($"leaf {this.n}"); } }
struct node : owning { var a: leaf; var b: leaf; }
def node::close(&mut this): void { if this.a.n != 0 { println($"node {this.a.n}"); } }
def main(): void {
{ var held := box::new(node{ a = leaf{ n = 1 }, b = leaf{ n = 2 } }); }
{ var many := vector::<node>::new(); many.append(node{ a = leaf{ n = 3 }, b = leaf{ n = 4 } }); }
{ var kept := holder::make(); }
println("done");
}
module lib;
struct hidden : owning { var n: int; }
def hidden::close(&mut this): void { if this.n != 0 { println($"hidden {this.n}"); } }
pub struct holder : owning { var one: box<hidden>; var many: vector<hidden>; }
pub def holder::make(): holder {
var made := holder{ one = box::new(hidden{ n = 5 }), many = vector::<hidden>::new() };
made.many.append(hidden{ n = 6 });
return made;
}
pub def holder::close(&mut this): void {}