1
0
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:
Swastik Baranwal 2022-11-28 14:07:12 +05:30 committed by GitHub
parent d257e43932
commit 58e150df12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View 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 | }

View File

@ -0,0 +1,3 @@
for a in 1...10 {
println(a)
}

View File

@ -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)