From 2945629ed4d2e9a36092f1e4e4afc98d74fc13fd Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Fri, 3 Jan 2025 18:07:06 -0300 Subject: [PATCH] fix --- vlib/v/checker/checker.v | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 7375f82872e979..1b0df5a3020c3d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1386,13 +1386,6 @@ fn (mut c Checker) check_expr_option_or_result_call(expr ast.Expr, ret_type ast. c.check_expr_option_or_result_call(expr.expr, ret_type) } ast.AsCast { - if expr.expr is ast.Ident { - if !ret_type.has_flag(.option) && expr.expr.obj.typ.has_flag(.option) - && expr.expr.or_expr.kind == .absent { - c.error('variable `${expr.expr.name}` is an Option, it must be unwrapped first', - expr.expr.pos) - } - } c.check_expr_option_or_result_call(expr.expr, ret_type) } ast.ParExpr { @@ -2965,7 +2958,13 @@ pub fn (mut c Checker) expr(mut node ast.Expr) ast.Type { if !c.is_builtin_mod { c.table.used_features.as_cast = true } - c.check_expr_option_or_result_call(node.expr, node.typ) + if mut node.expr is ast.Ident { + if !node.typ.has_flag(.option) && node.expr.obj.typ.has_flag(.option) + && node.expr.or_expr.kind == .absent { + c.error('variable `${node.expr.name}` is an Option, it must be unwrapped first', + node.expr.pos) + } + } if expr_type_sym.kind == .sum_type { c.ensure_type_exists(node.typ, node.pos) if !c.table.sumtype_has_variant(c.unwrap_generic(node.expr_type), c.unwrap_generic(node.typ),