parser: display correct position on boolean expression error (#8563)
parent
44ab0154b2
commit
6b776e686e
|
@ -17,17 +17,17 @@ vlib/v/checker/tests/infix_err.vv:9:9: error: `+` cannot be used with `?string`
|
||||||
8 | _ = f() + ''
|
8 | _ = f() + ''
|
||||||
9 | _ = f() + f()
|
9 | _ = f() + f()
|
||||||
| ^
|
| ^
|
||||||
10 |
|
10 |
|
||||||
11 | _ = 4 + g()
|
11 | _ = 4 + g()
|
||||||
vlib/v/checker/tests/infix_err.vv:11:7: error: `+` cannot be used with `?int`
|
vlib/v/checker/tests/infix_err.vv:11:7: error: `+` cannot be used with `?int`
|
||||||
9 | _ = f() + f()
|
9 | _ = f() + f()
|
||||||
10 |
|
10 |
|
||||||
11 | _ = 4 + g()
|
11 | _ = 4 + g()
|
||||||
| ^
|
| ^
|
||||||
12 | _ = int(0) + g() // FIXME not detected
|
12 | _ = int(0) + g() // FIXME not detected
|
||||||
13 | _ = g() + int(3)
|
13 | _ = g() + int(3)
|
||||||
vlib/v/checker/tests/infix_err.vv:12:12: error: unwrapped optional cannot be used in an infix expression
|
vlib/v/checker/tests/infix_err.vv:12:12: error: unwrapped optional cannot be used in an infix expression
|
||||||
10 |
|
10 |
|
||||||
11 | _ = 4 + g()
|
11 | _ = 4 + g()
|
||||||
12 | _ = int(0) + g() // FIXME not detected
|
12 | _ = int(0) + g() // FIXME not detected
|
||||||
| ^
|
| ^
|
||||||
|
@ -45,16 +45,37 @@ vlib/v/checker/tests/infix_err.vv:14:9: error: `+` cannot be used with `?int`
|
||||||
13 | _ = g() + int(3)
|
13 | _ = g() + int(3)
|
||||||
14 | _ = g() + 3
|
14 | _ = g() + 3
|
||||||
| ^
|
| ^
|
||||||
15 |
|
15 |
|
||||||
16 | // binary operands
|
16 | // binary operands
|
||||||
vlib/v/checker/tests/infix_err.vv:17:5: error: left operand for `&&` is not a boolean
|
vlib/v/checker/tests/infix_err.vv:17:5: error: left operand for `&&` is not a boolean
|
||||||
15 |
|
15 |
|
||||||
16 | // binary operands
|
16 | // binary operands
|
||||||
17 | _ = 1 && 2
|
17 | _ = 1 && 2
|
||||||
| ^
|
| ^
|
||||||
18 | _ = true || 2
|
18 | _ = true || 2
|
||||||
|
19 |
|
||||||
vlib/v/checker/tests/infix_err.vv:18:13: error: right operand for `||` is not a boolean
|
vlib/v/checker/tests/infix_err.vv:18:13: error: right operand for `||` is not a boolean
|
||||||
16 | // binary operands
|
16 | // binary operands
|
||||||
17 | _ = 1 && 2
|
17 | _ = 1 && 2
|
||||||
18 | _ = true || 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
|
||||||
|
| ~~
|
||||||
|
|
|
@ -16,3 +16,9 @@ _ = g() + 3
|
||||||
// binary operands
|
// binary operands
|
||||||
_ = 1 && 2
|
_ = 1 && 2
|
||||||
_ = true || 2
|
_ = true || 2
|
||||||
|
|
||||||
|
// boolean expressions
|
||||||
|
_ = 1 == 1 && 2 == 2 || 3 == 3
|
||||||
|
_ = 1 == 1
|
||||||
|
&& 2 == 2 || 3 == 3
|
||||||
|
&& 4 == 4
|
||||||
|
|
|
@ -397,12 +397,6 @@ fn (mut p Parser) infix_expr(left ast.Expr) ast.Expr {
|
||||||
}
|
}
|
||||||
precedence := p.tok.precedence()
|
precedence := p.tok.precedence()
|
||||||
mut pos := p.tok.position()
|
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()
|
p.next()
|
||||||
mut right := ast.Expr{}
|
mut right := ast.Expr{}
|
||||||
prev_expecting_type := p.expecting_type
|
prev_expecting_type := p.expecting_type
|
||||||
|
|
Loading…
Reference in New Issue