From 07e3699700b7d7d241f23bfd4f5e4d2c2859f537 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 5 Nov 2019 18:56:19 +0300 Subject: [PATCH] parser: do not allow number => bool casts --- vlib/compiler/gen_c.v | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vlib/compiler/gen_c.v b/vlib/compiler/gen_c.v index 93ba15683a..c4a40ff392 100644 --- a/vlib/compiler/gen_c.v +++ b/vlib/compiler/gen_c.v @@ -516,6 +516,9 @@ fn (p mut Parser) cast(typ string) { p.cgen.set_placeholder(pos, '*($typ*)(') } else { + if (is_number_type(expr_typ) || is_float_type(expr_typ)) && typ == 'bool' { + p.error('cannot cast a number to `bool`') + } p.cgen.set_placeholder(pos, '($typ)(') } p.check(.rpar)