From c4ff0d565b6f221e5f9634e17f7b018c0dc1b040 Mon Sep 17 00:00:00 2001 From: Daren Liang Date: Fri, 8 Nov 2019 12:26:08 -0500 Subject: [PATCH] parser: check mul and div operations on str variables --- vlib/compiler/expression.v | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vlib/compiler/expression.v b/vlib/compiler/expression.v index 0105810214..4ff7531caa 100644 --- a/vlib/compiler/expression.v +++ b/vlib/compiler/expression.v @@ -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)