parser: & and | type check

pull/2671/head
Alexander Medvednikov 2019-11-06 21:20:37 +03:00
parent 0f0bef2d33
commit 7c70f3df93
1 changed files with 9 additions and 5 deletions

View File

@ -1469,7 +1469,6 @@ fn (p mut Parser) bool_expression() string {
p.check_types(p.bterm(), typ) p.check_types(p.bterm(), typ)
if typ != 'bool' { if typ != 'bool' {
p.error('logical operators `&&` and `||` require booleans') p.error('logical operators `&&` and `||` require booleans')
} }
} }
if typ == '' { if typ == '' {
@ -2363,12 +2362,12 @@ fn (p mut Parser) indot_expr() string {
} }
// `typ` is element's type // `typ` is element's type
if is_map { if is_map {
p.cgen.set_placeholder(ph, '_IN_MAP( (') p.cgen.set_placeholder(ph, '(_IN_MAP( (')
} }
else { else {
p.cgen.set_placeholder(ph, '_IN($typ, (') p.cgen.set_placeholder(ph, '(_IN($typ, (')
} }
p.gen(')') p.gen('))')
return 'bool' return 'bool'
} }
return typ return typ
@ -2474,7 +2473,12 @@ fn (p mut Parser) expression() string {
if is_str && tok_op != .plus { if is_str && tok_op != .plus {
p.error('strings only support `+` operator') p.error('strings only support `+` operator')
} }
p.check_types(p.term(), typ) expr_type := p.term()
if (tok_op in [.pipe, .amp]) && !(is_integer_type(expr_type) &&
is_integer_type(typ)) {
p.error('operators `&` and `|` are defined only on integer types')
}
p.check_types(expr_type, typ)
if (is_str || is_ustr) && tok_op == .plus && !p.is_js { if (is_str || is_ustr) && tok_op == .plus && !p.is_js {
p.gen(')') p.gen(')')
} }