@@ -457,7 +457,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
457
457
} else if node.left ! in [ast.Ident, ast.SelectorExpr, ast.ComptimeSelector]
458
458
&& (left_type.has_flag (.option) || right_type.has_flag (.option)) {
459
459
opt_comp_pos := if left_type.has_flag (.option) { left_pos } else { right_pos }
460
- c.error ('unwrapped option cannot be compared in an infix expression' ,
460
+ c.error ('unwrapped Option cannot be compared in an infix expression' ,
461
461
opt_comp_pos)
462
462
}
463
463
}
@@ -471,6 +471,11 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
471
471
if ! node.is_stmt {
472
472
c.error ('array append cannot be used in an expression' , node.pos)
473
473
}
474
+ if left_type.has_flag (.option) && node.left is ast.Ident
475
+ && (node.left as ast.Ident ).or_expr.kind == .absent {
476
+ c.error ('unwrapped Option cannot be used in an infix expression' ,
477
+ node.pos)
478
+ }
474
479
// `array << elm`
475
480
c.check_expr_opt_call (node.right, right_type)
476
481
node.auto_locked , _ = c.fail_if_immutable (node.left)
@@ -695,15 +700,15 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
695
700
opt_infix_pos := if left_is_option { left_pos } else { right_pos }
696
701
if (node.left ! in [ast.Ident, ast.SelectorExpr, ast.ComptimeSelector]
697
702
|| node.op in [.eq, .ne, .lt, .gt, .le, .ge]) && right_sym.kind != .none_ {
698
- c.error ('unwrapped option cannot be used in an infix expression' , opt_infix_pos)
703
+ c.error ('unwrapped Option cannot be used in an infix expression' , opt_infix_pos)
699
704
}
700
705
}
701
706
702
707
left_is_result := left_type.has_flag (.result)
703
708
right_is_result := right_type.has_flag (.result)
704
709
if left_is_result || right_is_result {
705
710
opt_infix_pos := if left_is_result { left_pos } else { right_pos }
706
- c.error ('unwrapped result cannot be used in an infix expression' , opt_infix_pos)
711
+ c.error ('unwrapped Result cannot be used in an infix expression' , opt_infix_pos)
707
712
}
708
713
709
714
// Dual sides check (compatibility check)
0 commit comments