From b79588dc6962d8793d7728b21f26ce1c156fe61b Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 7 Dec 2019 23:05:54 +0300 Subject: [PATCH] handle bad value in `if x := opt() {` --- vlib/compiler/if_match.v | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vlib/compiler/if_match.v b/vlib/compiler/if_match.v index 3bf7b46bab..415882fd98 100644 --- a/vlib/compiler/if_match.v +++ b/vlib/compiler/if_match.v @@ -235,6 +235,9 @@ fn (p mut Parser) if_statement(is_expr bool, elif_depth int) string { p.check(.decl_assign) p.is_var_decl = true option_type, expr := p.tmp_expr()// := p.bool_expression() + if !option_type.starts_with('Option_') { + p.error('`if x := opt() {` syntax requires a function that returns an optional value') + } p.is_var_decl = false typ := option_type[7..] // Option_User tmp = get_user(1);