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);