value if/loop follow-ups
This commit is contained in:
+9
-8
@@ -2131,10 +2131,11 @@ yield_compiles_and_runs :: proc(t: ^testing.T) {
|
||||
status := compiler_core.compile_package("examples/programs/yield", output)
|
||||
testing.expect_value(t, status, 0)
|
||||
state := run_executable(output)
|
||||
// Value blocks (untyped/typed, defer-spill, reassignment) plus value if-statements
|
||||
// (untyped/typed/reassign/else-if/defer) and value loops (a labeled `for` search
|
||||
// yielding `?usize` on both the found and not-found paths, and a labeled `while`)
|
||||
// together produce 42.
|
||||
// Value blocks (untyped/typed, defer-spill, reassignment), value if-statements
|
||||
// (untyped/typed/reassign/else-if/defer, a branch that `return`s instead of yielding,
|
||||
// and an unwrap-`if` as a value source), `orelse`, and value loops (a labeled `for`
|
||||
// search yielding `?usize` on the found/not-found paths, a labeled `while`, and an
|
||||
// untyped loop that yields `none` before any concrete value) together produce 42.
|
||||
testing.expect_value(t, state.exit_code, 42)
|
||||
}
|
||||
|
||||
@@ -2179,9 +2180,9 @@ yield_misuse_is_diagnosed :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
yield_control_flow_is_diagnosed :: proc(t: ^testing.T) {
|
||||
// Value if/loop misuse (milestone 20.5): an `if` value without an `else`; a
|
||||
// branch that does not end in `yield`; a value loop whose body lacks a trailing
|
||||
// fall-through `yield`; and a `yield :label` with no matching value loop.
|
||||
// Value if/loop misuse: an `if` value without an `else`; a branch that neither
|
||||
// yields nor exits on every path (milestone 20.6); a value loop whose body lacks a
|
||||
// trailing fall-through `yield`; and a `yield :label` with no matching value loop.
|
||||
text := `main :: func() i32 {
|
||||
noelse :: if (true) {
|
||||
yield 1
|
||||
@@ -2218,7 +2219,7 @@ yield_control_flow_is_diagnosed :: proc(t: ^testing.T) {
|
||||
stray_label := false
|
||||
for diagnostic in diagnostics.items {
|
||||
no_else = no_else || strings.contains(diagnostic.message, "an 'if' used as a value must have an 'else'")
|
||||
branch_no_yield = branch_no_yield || strings.contains(diagnostic.message, "a value block must end with an explicit 'yield'")
|
||||
branch_no_yield = branch_no_yield || strings.contains(diagnostic.message, "a value branch must end with 'yield' or exit on every path")
|
||||
loop_no_yield = loop_no_yield || strings.contains(diagnostic.message, "a value loop's body must end with a 'yield'")
|
||||
stray_label = stray_label || strings.contains(diagnostic.message, "no enclosing value loop is labeled 'stray'")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user