mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix a & b == c
precedence
This commit is contained in:
parent
e957fd6f30
commit
f724a956b3
@ -66,6 +66,15 @@ fn test_str_methods() {
|
||||
assert u64(-1).str() == '18446744073709551615'
|
||||
}
|
||||
|
||||
fn test_and() {
|
||||
c:=[1,2,3,4,5]
|
||||
assert c[0] & 1 != 0
|
||||
assert c[1] & 1 == 0
|
||||
assert c[2] & 1 != 0
|
||||
assert c[3] & 1 == 0
|
||||
assert c[4] & 1 != 0
|
||||
}
|
||||
|
||||
/*
|
||||
fn test_cmp() {
|
||||
assert 1 ≠ 2
|
||||
|
@ -473,14 +473,22 @@ fn (p mut Parser) expression() string {
|
||||
p.error('strings only support `+` operator')
|
||||
}
|
||||
expr_type := p.term()
|
||||
if (tok_op in [.pipe, .amp, .xor]) && !(is_integer_type(expr_type) &&
|
||||
is_integer_type(typ)) {
|
||||
mut open := false
|
||||
if tok_op in [.pipe, .amp, .xor] {
|
||||
if !(is_integer_type(expr_type) && is_integer_type(typ)) {
|
||||
p.error('operator ${tok_op.str()} is defined only on integer types')
|
||||
}
|
||||
p.cgen.set_placeholder(ph, '(')
|
||||
open = true
|
||||
}
|
||||
p.check_types(expr_type, typ)
|
||||
if (is_str || is_ustr) && tok_op == .plus && !p.is_js {
|
||||
p.gen(')')
|
||||
}
|
||||
if open {
|
||||
p.gen(')')
|
||||
|
||||
}
|
||||
// Make sure operators are used with correct types
|
||||
if !p.pref.translated && !is_str && !is_ustr && !is_num {
|
||||
T := p.table.find_type(typ)
|
||||
|
Loading…
Reference in New Issue
Block a user