parser: check mul and div operations on str variables

pull/2705/head
Daren Liang 2019-11-08 12:26:08 -05:00 committed by Alexander Medvednikov
parent bc826173cc
commit c4ff0d565b
1 changed files with 3 additions and 4 deletions

View File

@ -488,14 +488,13 @@ fn (p mut Parser) term() string {
p.gen(tok.str())// + ' /*op2*/ ')
oph := p.cgen.add_placeholder()
p.fgen(' ' + tok.str() + ' ')
if (is_mul || is_div) && p.tok == .str {
p.error('operator ${tok.str()} cannot be used on strings')
}
if (is_div || is_mod) && p.tok == .number && p.lit == '0' {
p.error('division or modulo by zero')
}
expr_type := p.unary()
if (is_mul || is_div) && expr_type == 'string' {
p.error('operator ${tok.str()} cannot be used on strings')
}
if !is_primitive_type(expr_type) && expr_type == typ {
p.check_types(expr_type, typ)
T := p.table.find_type(typ)