From 0f0bef2d3396e25a32f175ee26cb8bb7ace159b1 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 6 Nov 2019 20:47:03 +0300 Subject: [PATCH] parser: more typing checks --- vlib/compiler/parser.v | 7 +++++++ vlib/math/math_test.v | 3 +++ 2 files changed, 10 insertions(+) diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index b5a2a933a3..d187072115 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -1467,6 +1467,10 @@ fn (p mut Parser) bool_expression() string { } p.check_space(p.tok) p.check_types(p.bterm(), typ) + if typ != 'bool' { + p.error('logical operators `&&` and `||` require booleans') + + } } if typ == '' { println('curline:') @@ -2467,6 +2471,9 @@ fn (p mut Parser) expression() string { p.gen(',') } } + if is_str && tok_op != .plus { + p.error('strings only support `+` operator') + } p.check_types(p.term(), typ) if (is_str || is_ustr) && tok_op == .plus && !p.is_js { p.gen(')') diff --git a/vlib/math/math_test.v b/vlib/math/math_test.v index a50284ffa3..e2393fd542 100644 --- a/vlib/math/math_test.v +++ b/vlib/math/math_test.v @@ -53,4 +53,7 @@ fn test_mod() { assert 4 % 2 == 0 x := 2 assert u64(5) % x == 1 + mut a := 10 + a %= 2 + assert a == 0 }