mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix error of -foo.bar()
(#9646)
This commit is contained in:
parent
67ec33218e
commit
e6a67e7172
@ -507,11 +507,7 @@ fn (mut p Parser) prefix_expr() ast.PrefixExpr {
|
|||||||
// p.warn('unsafe')
|
// p.warn('unsafe')
|
||||||
// }
|
// }
|
||||||
p.next()
|
p.next()
|
||||||
mut right := if op == .minus {
|
mut right := p.expr(int(token.Precedence.prefix))
|
||||||
p.expr(int(token.Precedence.call))
|
|
||||||
} else {
|
|
||||||
p.expr(int(token.Precedence.prefix))
|
|
||||||
}
|
|
||||||
p.is_amp = false
|
p.is_amp = false
|
||||||
if mut right is ast.CastExpr {
|
if mut right is ast.CastExpr {
|
||||||
right.in_prexpr = true
|
right.in_prexpr = true
|
||||||
|
29
vlib/v/tests/prefix_expr_test.v
Normal file
29
vlib/v/tests/prefix_expr_test.v
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
fn value(n int) int {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
n int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (foo Foo) value() int {
|
||||||
|
return foo.n
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_negative() {
|
||||||
|
one := 1
|
||||||
|
negative_one := -1
|
||||||
|
assert -one == negative_one
|
||||||
|
assert one == -negative_one
|
||||||
|
|
||||||
|
assert -value(1) == -1
|
||||||
|
|
||||||
|
// issue #9643
|
||||||
|
foo := Foo{1}
|
||||||
|
assert -foo.value() == -1
|
||||||
|
assert -(foo.value()) == -1
|
||||||
|
|
||||||
|
arr := [1, 2, 3]
|
||||||
|
assert -arr[0] == -1
|
||||||
|
assert -arr[1] == -2
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user