diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c837f2c7e93971..62be8f886cb947 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) @@ -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 {