Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 3, 2025
1 parent fe26aad commit 2945629
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 2945629

Please sign in to comment.