parser: fix a bug with & and ==

pull/2927/head
Alexander Medvednikov 2019-11-29 23:18:10 +03:00
parent 4c11eb5ddc
commit 850788c4bb
1 changed files with 4 additions and 3 deletions

View File

@ -473,13 +473,15 @@ fn (p mut Parser) expression() string {
p.error('strings only support `+` operator')
}
expr_type := p.term()
mut open := false
open := tok_op == .amp && p.tok in [.eq, .ne] // force precedence `(a & b) == c` //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')
}
//open = true
}
if open {
p.cgen.set_placeholder(ph, '(')
open = true
}
p.check_types(expr_type, typ)
if (is_str || is_ustr) && tok_op == .plus && !p.is_js {
@ -487,7 +489,6 @@ fn (p mut Parser) expression() string {
}
if open {
p.gen(')')
}
// Make sure operators are used with correct types
if !p.pref.translated && !is_str && !is_ustr && !is_num {