1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: check mul and div operations on str variables

This commit is contained in:
Daren Liang 2019-11-08 12:26:08 -05:00 committed by Alexander Medvednikov
parent bc826173cc
commit c4ff0d565b

View File

@ -488,14 +488,13 @@ fn (p mut Parser) term() string {
p.gen(tok.str())// + ' /*op2*/ ') p.gen(tok.str())// + ' /*op2*/ ')
oph := p.cgen.add_placeholder() oph := p.cgen.add_placeholder()
p.fgen(' ' + tok.str() + ' ') 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' { if (is_div || is_mod) && p.tok == .number && p.lit == '0' {
p.error('division or modulo by zero') p.error('division or modulo by zero')
} }
expr_type := p.unary() 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 { if !is_primitive_type(expr_type) && expr_type == typ {
p.check_types(expr_type, typ) p.check_types(expr_type, typ)
T := p.table.find_type(typ) T := p.table.find_type(typ)