diff --git a/vlib/v/checker/for.v b/vlib/v/checker/for.v index fd5ac5cfed4d7e..4c5301d45239c1 100644 --- a/vlib/v/checker/for.v +++ b/vlib/v/checker/for.v @@ -22,9 +22,22 @@ fn (mut c Checker) for_c_stmt(mut node ast.ForCStmt) { for right in assign.right { if right is ast.CallExpr { - if right.or_block.stmts.len > 0 { - c.error('options are not allowed in `for statement increment` (yet)', - right.pos) + match right.or_block.kind { + .block { + if right.or_block.stmts.len > 0 { + c.error('options are not allowed in `for statement increment` (yet)', + right.pos) + } + } + .propagate_result { + c.error('propagating errors in `for statement increment` is not allowed (yet)', + right.pos) + } + .propagate_option { + c.error('propagating options in `for statement increment` is not allowed (yet)', + right.pos) + } + .absent {} } } } diff --git a/vlib/v/checker/tests/for_c_stmt_with_option_propagation.out b/vlib/v/checker/tests/for_c_stmt_with_option_propagation.out new file mode 100644 index 00000000000000..5fa4407e4e1919 --- /dev/null +++ b/vlib/v/checker/tests/for_c_stmt_with_option_propagation.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/for_c_stmt_with_option_propagation.vv:8:24: error: propagating options in `for statement increment` is not allowed (yet) + 6 | mut pos := 0 + 7 | + 8 | for ; pos > 10; pos = foo()? { + | ~~~~~ + 9 | println(pos) + 10 | } diff --git a/vlib/v/checker/tests/for_c_stmt_with_option_propagation.vv b/vlib/v/checker/tests/for_c_stmt_with_option_propagation.vv new file mode 100644 index 00000000000000..4426e1a7301366 --- /dev/null +++ b/vlib/v/checker/tests/for_c_stmt_with_option_propagation.vv @@ -0,0 +1,11 @@ +fn foo() ?int { + return 5 +} + +fn main() { + mut pos := 0 + + for ; pos > 10; pos = foo()? { + println(pos) + } +} diff --git a/vlib/v/checker/tests/for_c_stmt_with_result_propagation.out b/vlib/v/checker/tests/for_c_stmt_with_result_propagation.out new file mode 100644 index 00000000000000..24cf00095e5a29 --- /dev/null +++ b/vlib/v/checker/tests/for_c_stmt_with_result_propagation.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/for_c_stmt_with_result_propagation.vv:8:24: error: propagating errors in `for statement increment` is not allowed (yet) + 6 | mut pos := 0 + 7 | + 8 | for ; pos > 10; pos = foo()! { + | ~~~~~ + 9 | println(pos) + 10 | } diff --git a/vlib/v/checker/tests/for_c_stmt_with_result_propagation.vv b/vlib/v/checker/tests/for_c_stmt_with_result_propagation.vv new file mode 100644 index 00000000000000..2adaa732fb5b48 --- /dev/null +++ b/vlib/v/checker/tests/for_c_stmt_with_result_propagation.vv @@ -0,0 +1,11 @@ +fn foo() !int { + return 5 +} + +fn main() { + mut pos := 0 + + for ; pos > 10; pos = foo()! { + println(pos) + } +}