unions (untagged)

This commit is contained in:
2026-06-28 09:16:57 +02:00
parent 3007910526
commit f328c44154
6 changed files with 77 additions and 5 deletions
+13
View File
@@ -2139,6 +2139,19 @@ yield_compiles_and_runs :: proc(t: ^testing.T) {
testing.expect_value(t, state.exit_code, 42)
}
@(test)
native_union_compiles_and_runs :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-unions"
defer _ = os.remove(output)
status := compiler_core.compile_package("examples/programs/unions", output)
testing.expect_value(t, status, 0)
state := run_executable(output)
// A native untagged union (`Val :: union { n i32, f f64 }`) constructed via a keyed
// literal, stored into a local, and read back through field access reinterprets the
// carrier and yields 42 (declaration → construct → store → load → field read).
testing.expect_value(t, state.exit_code, 42)
}
@(test)
yield_misuse_is_diagnosed :: proc(t: ^testing.T) {
// A value block that does not end in `yield`, and a `yield` nested inside an