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 strings

This commit is contained in:
Daren Liang 2019-11-07 20:32:25 -05:00 committed by Alexander Medvednikov
parent db4a7edf3a
commit f5438477df

View File

@ -481,13 +481,16 @@ fn (p mut Parser) term() string {
}
for p.tok == .mul || p.tok == .div || p.tok == .mod {
tok := p.tok
is_mul := tok == .mul
is_div := tok == .div
is_mod := tok == .mod
// is_mul := tok == .mod
p.next()
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')
}