labeled block statements
This commit is contained in:
+12
-3
@@ -2133,8 +2133,9 @@ yield_compiles_and_runs :: proc(t: ^testing.T) {
|
||||
state := run_executable(output)
|
||||
// Value blocks, value if-statements (incl. `return` branches and unwrap-`if`),
|
||||
// `orelse`, value loops, labeled value blocks (`blk: { … yield :blk v }`, incl.
|
||||
// defer-capture and `{T,none}` → optional), and outer-loop control (`yield :outer v`
|
||||
// and `break :outer` from an inner loop) together produce 42.
|
||||
// defer-capture, `{T,none}` → optional, and `none` before a concrete yield that uses a
|
||||
// block local), outer-loop control (`yield :outer v` / `break :outer`), and labeled
|
||||
// block statements exited via `break :blk` together produce 42.
|
||||
testing.expect_value(t, state.exit_code, 42)
|
||||
}
|
||||
|
||||
@@ -2182,7 +2183,8 @@ yield_control_flow_is_diagnosed :: proc(t: ^testing.T) {
|
||||
// Value if/loop/block misuse: an `if` value without an `else`; a branch that neither
|
||||
// yields nor exits on every path (20.6); a value loop whose body lacks a trailing
|
||||
// fall-through `yield`; a `yield :label` with no matching value loop; a labeled value
|
||||
// block that does not yield on every path, and a `break :label` naming no loop (20.7).
|
||||
// block that does not yield on every path; a `break :label` naming no loop; and a
|
||||
// `continue :label` targeting a block (not a loop).
|
||||
text := `main :: func() i32 {
|
||||
noelse :: if (true) {
|
||||
yield 1
|
||||
@@ -2205,6 +2207,9 @@ yield_control_flow_is_diagnosed :: proc(t: ^testing.T) {
|
||||
for 0..10 |m| {
|
||||
break :nope
|
||||
}
|
||||
scope: {
|
||||
continue :scope
|
||||
}
|
||||
return noelse + badbranch + noloopyield + noblockyield
|
||||
}
|
||||
`
|
||||
@@ -2226,6 +2231,7 @@ yield_control_flow_is_diagnosed :: proc(t: ^testing.T) {
|
||||
stray_label := false
|
||||
block_no_yield := false
|
||||
bad_break_label := false
|
||||
continue_block := 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 branch must end with 'yield' or exit on every path")
|
||||
@@ -2233,6 +2239,8 @@ yield_control_flow_is_diagnosed :: proc(t: ^testing.T) {
|
||||
stray_label = stray_label || strings.contains(diagnostic.message, "no enclosing value loop or block is labeled 'stray'")
|
||||
block_no_yield = block_no_yield || strings.contains(diagnostic.message, "a labeled value block must 'yield' on every path")
|
||||
bad_break_label = bad_break_label || strings.contains(diagnostic.message, "no enclosing loop is labeled 'nope'")
|
||||
// `continue :scope` targets a labeled block, which is not a loop.
|
||||
continue_block = continue_block || strings.contains(diagnostic.message, "no enclosing loop is labeled 'scope'")
|
||||
}
|
||||
testing.expect(t, no_else)
|
||||
testing.expect(t, branch_no_yield)
|
||||
@@ -2240,6 +2248,7 @@ yield_control_flow_is_diagnosed :: proc(t: ^testing.T) {
|
||||
testing.expect(t, stray_label)
|
||||
testing.expect(t, block_no_yield)
|
||||
testing.expect(t, bad_break_label)
|
||||
testing.expect(t, continue_block)
|
||||
}
|
||||
|
||||
@(test)
|
||||
|
||||
Reference in New Issue
Block a user