Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Oct 12, 2024
1 parent 92c443b commit 671c5fd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ fn (mut c Checker) check_expr_option_or_result_call(expr ast.Expr, ret_type ast.
'a Result'
}
with_modifier := if expr.typ.has_flag(.option) { '?' } else { '!' }
if expr.or_block.kind == .absent {
if expr.typ.has_flag(.result) && expr.or_block.kind == .absent {
if c.inside_defer {
c.error('field `${expr.field_name}` is ${with_modifier_kind}, so it should have an `or {}` block at the end',
expr.pos)
Expand Down Expand Up @@ -1278,8 +1278,15 @@ fn (mut c Checker) check_expr_option_or_result_call(expr ast.Expr, ret_type ast.
c.check_or_expr(expr.or_expr, ret_type, ret_type.set_flag(.result),
expr)
}
} else if expr.left_type.has_option_or_result() {
c.check_expr_option_or_result_call(expr.left, ret_type)
} else if expr.left is ast.SelectorExpr && expr.left_type.has_option_or_result() {
with_modifier_kind := if expr.left_type.has_flag(.option) {
'an Option'
} else {
'a Result'
}
with_modifier := if expr.left_type.has_flag(.option) { '?' } else { '!' }
c.error('field `${expr.left.field_name}` is ${with_modifier_kind}, so it should have either an `or {}` block, or `${with_modifier}` at the end',
expr.left.pos)
}
}
ast.CastExpr {
Expand Down

0 comments on commit 671c5fd

Please sign in to comment.