tests: preserve rejection contexts and normalize callee effects

This commit is contained in:
dev committed 2026-10-08 19:41:01 +03:00
1 parent 06d8a1a76a
commit fd92604f36
11 files changed
+344 -35

No files matched your search

@@ -2,10 +2,11 @@
// phase: 6
// spec: docs/spec/08-verifier.md §7; docs/spec/15-source-language.md §10
module test.nominal_queries
struct N0 { a: N1, b: N1 }
struct N1 { a: N2, b: N2 }
struct N2 { a: N3, b: N3 }
struct N3 { a: N4, b: N4 }
// AIR twin: nominal_queries/diamond_21_u64.air
struct N0 { a: N1, b: N1 } // diagnostic here
struct N1 { a: N2, b: N2 } // diagnostic here
struct N2 { a: N3, b: N3 } // diagnostic here
struct N3 { a: N4, b: N4 } // diagnostic here
struct N4 { a: N5, b: N5 }
struct N5 { a: N6, b: N6 }
struct N6 { a: N7, b: N7 }
@@ -0,0 +1,13 @@
// own.new receives cap<fs.read> where the allocation needs cap<mem.alloc>.
// phase: 6
// spec: docs/spec/05-effects-and-capabilities.md §10.5
// expect: reject E3201
// AIR twin: phase2/reject/alloc_wrong_capability.air
module test.source_alloc_wrong_capability
fn f(heap: cap<fs.read>) -> void effects [mem.alloc] {
match own.new(1u64, heap) { // diagnostic here: own.new
ok(o) => { own.free(move o); }
err(e) => {}
}
}
fn main() -> u64 effects [] { return 0u64; }
@@ -0,0 +1,16 @@
// Failed send returns the owner under a new name on both failure edges.
// phase: 6
// spec: docs/spec/04-concurrency-and-atomics.md §38
// AIR twin: phase3/reject/channels_use_after_send.air
// expect: reject E2001
module test.source_use_after_failed_send
fn f(tx: mut<sender<own<u64>>>, o: own<u64>) -> u64 effects [task.wait] {
let back = match channel.send(tx, move o) {
ok => { return 0u64; }
closed(value) => move value,
cancelled(value) => move value,
};
{ ref old = o; } // diagnostic here: ref old
return own.take(move back);
}
fn main() -> u64 effects [] { return 0u64; }
@@ -0,0 +1,11 @@
// atomic does not imply atomic.weak: effect sets are flat.
// phase: 6
// spec: docs/spec/05-effects-and-capabilities.md §9.2/§9.3
// expect: reject E3101
// AIR twin: phase2/reject/flat_effects.air
module test.source_flat_effects
fn relaxed_work() -> void effects [atomic.weak] {}
fn f() -> void effects [atomic] {
relaxed_work(); // diagnostic here
}
fn main() -> u64 effects [] { return 0u64; }
@@ -0,0 +1,19 @@
// An opened file is moved into a consuming call and then borrowed.
// phase: 6
// spec: docs/spec/06-resources-and-errors.md §6.2
// expect: reject E2001
// AIR twin: phase2/reject/resource_use_after_move.air
module test.source_resource_use_after_move
fn take(file: file<read>) -> void effects [] {
fs.close(move file) or trap;
}
fn f(c: cap<fs.read>, p: slice<u8>) -> void effects [fs.read] {
match fs.open_read(c, p) {
ok(file) => {
take(move file);
{ mut m = file; } // diagnostic here: mut m
}
err(e) => {}
}
}
fn main() -> u64 effects [] { return 0u64; }
@@ -0,0 +1,11 @@
// The caller does not declare the effect of its callee.
// phase: 6
// spec: docs/spec/05-effects-and-capabilities.md §9.3
// expect: reject E3101
// AIR twin: phase2/reject/undeclared_effect.air
module test.source_undeclared_effect
fn emit() -> void effects [io.write] {}
fn f() -> void effects [] {
emit(); // diagnostic here
}
fn main() -> u64 effects [] { return 0u64; }