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

19 lines
696 B
Plaintext

import std::io;
struct noisy : owning { var name: span<u8>; }
def noisy::new(name: span<u8>): noisy { return noisy { name = name }; }
def noisy::close(&mut this): void { println($"close {this.name}"); }
def noisy::rename(&mut this, name: span<u8>): void { this.name = name; }
union held { var code: i64; var one: noisy; }
def main(): void {
var h: held = noisy::new("a");
match h {
one(&mut got) => { println($"holds {got.name}"); got.rename("renamed"); }
code(n) => { println($"code {n}"); }
}
if h is one(&got) { println($"still {got.name}"); }
var c: held = 7;
if c is one(&got) { println("wrong"); }
if c is code(n) { println($"code {n}"); }
println("end");
}