Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix propagation checking in c-style for loop increment #19636

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions vlib/v/checker/for.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/for_c_stmt_with_option_propagation.out
Original file line number Diff line number Diff line change
@@ -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 | }
11 changes: 11 additions & 0 deletions vlib/v/checker/tests/for_c_stmt_with_option_propagation.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn foo() ?int {
return 5
}

fn main() {
mut pos := 0

for ; pos > 10; pos = foo()? {
println(pos)
}
}
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/for_c_stmt_with_result_propagation.out
Original file line number Diff line number Diff line change
@@ -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 | }
11 changes: 11 additions & 0 deletions vlib/v/checker/tests/for_c_stmt_with_result_propagation.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn foo() !int {
return 5
}

fn main() {
mut pos := 0

for ; pos > 10; pos = foo()! {
println(pos)
}
}
Loading