parser: display correct position on boolean expression error (#8563)

pull/8591/head
zakuro 2021-02-06 00:52:35 +09:00 committed by GitHub
parent 44ab0154b2
commit 6b776e686e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 11 deletions

View File

@ -53,8 +53,29 @@ vlib/v/checker/tests/infix_err.vv:17:5: error: left operand for `&&` is not a bo
17 | _ = 1 && 2
| ^
18 | _ = true || 2
19 |
vlib/v/checker/tests/infix_err.vv:18:13: error: right operand for `||` is not a boolean
16 | // binary operands
17 | _ = 1 && 2
18 | _ = true || 2
| ^
19 |
20 | // boolean expressions
vlib/v/checker/tests/infix_err.vv:21:22: error: use `()` to make the boolean expression clear
19 |
20 | // boolean expressions
21 | _ = 1 == 1 && 2 == 2 || 3 == 3
| ~~
22 | _ = 1 == 1
23 | && 2 == 2 || 3 == 3
vlib/v/checker/tests/infix_err.vv:23:12: error: use `()` to make the boolean expression clear
21 | _ = 1 == 1 && 2 == 2 || 3 == 3
22 | _ = 1 == 1
23 | && 2 == 2 || 3 == 3
| ~~
24 | && 4 == 4
vlib/v/checker/tests/infix_err.vv:24:2: error: use `()` to make the boolean expression clear
22 | _ = 1 == 1
23 | && 2 == 2 || 3 == 3
24 | && 4 == 4
| ~~

View File

@ -16,3 +16,9 @@ _ = g() + 3
// binary operands
_ = 1 && 2
_ = true || 2
// boolean expressions
_ = 1 == 1 && 2 == 2 || 3 == 3
_ = 1 == 1
&& 2 == 2 || 3 == 3
&& 4 == 4

View File

@ -397,12 +397,6 @@ fn (mut p Parser) infix_expr(left ast.Expr) ast.Expr {
}
precedence := p.tok.precedence()
mut pos := p.tok.position()
if left.position().line_nr < pos.line_nr {
pos = token.Position{
...pos
line_nr: left.position().line_nr
}
}
p.next()
mut right := ast.Expr{}
prev_expecting_type := p.expecting_type