mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: add a better error msg for using ...
, instead of ..
in for a in 1...10 {
(#16547)
This commit is contained in:
parent
d257e43932
commit
58e150df12
5
vlib/v/checker/tests/for_loop_range_inclusive_err.out
Normal file
5
vlib/v/checker/tests/for_loop_range_inclusive_err.out
Normal file
@ -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 | }
|
3
vlib/v/checker/tests/for_loop_range_inclusive_err.vv
Normal file
3
vlib/v/checker/tests/for_loop_range_inclusive_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
for a in 1...10 {
|
||||
println(a)
|
||||
}
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user