33-yield.ha (603B)
1 use rt::{compile, exited, EXIT_SUCCESS}; 2 3 fn basics() void = { 4 let x = { 5 yield 10; 6 }; 7 let y = :outer { 8 if (true) { 9 yield :outer, 20; 10 }; 11 abort(); 12 }; 13 assert(x == 10); 14 assert(y == 20); 15 }; 16 17 fn termination() void = { 18 :outer { 19 let x: int = if (true) { 20 yield :outer; 21 } else 1; 22 abort(); 23 }; 24 25 assert(compile( 26 "fn test() void = { let x: int = if (true) { yield; } else 1; };" 27 ) as exited != EXIT_SUCCESS); 28 }; 29 30 fn cast_lowering() void = { 31 let x: (int | void) = { 32 yield 10; 33 }; 34 assert(x as int == 10); 35 }; 36 37 export fn main() void = { 38 basics(); 39 termination(); 40 cast_lowering(); 41 };