diff --git a/vlib/v/checker/tests/for_loop_range_inclusive_err.out b/vlib/v/checker/tests/for_loop_range_inclusive_err.out new file mode 100644 index 0000000000..856021b471 --- /dev/null +++ b/vlib/v/checker/tests/for_loop_range_inclusive_err.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/for_loop_range_inclusive_err.vv:1:11: error: for loop only supports exclusive (`..`) ranges, not inclusive (`...`) + 1 | for a in 1...10 { + | ~~~ + 2 | println(a) + 3 | } diff --git a/vlib/v/checker/tests/for_loop_range_inclusive_err.vv b/vlib/v/checker/tests/for_loop_range_inclusive_err.vv new file mode 100644 index 0000000000..c89c6e8fb7 --- /dev/null +++ b/vlib/v/checker/tests/for_loop_range_inclusive_err.vv @@ -0,0 +1,3 @@ +for a in 1...10 { + println(a) +} diff --git a/vlib/v/parser/for.v b/vlib/v/parser/for.v index bb995da7a3..843cbed200 100644 --- a/vlib/v/parser/for.v +++ b/vlib/v/parser/for.v @@ -150,7 +150,10 @@ fn (mut p Parser) for_stmt() ast.Stmt { // TODO use RangeExpr mut high_expr := ast.empty_expr mut is_range := false - if p.tok.kind == .dotdot { + if p.tok.kind == .ellipsis { + p.error_with_pos('for loop only supports exclusive (`..`) ranges, not inclusive (`...`)', + p.tok.pos()) + } else if p.tok.kind == .dotdot { is_range = true p.next() high_expr = p.expr(0)