checker: check error for infix compare optional (#13701)
parent
54de04a916
commit
4c33003f86
|
@ -842,6 +842,9 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if left_type.has_flag(.optional) && right_type.has_flag(.optional) {
|
||||||
|
c.error('unwrapped optional cannot be compared in an infix expression',
|
||||||
|
left_right_pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.left_shift {
|
.left_shift {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/infix_compare_optional_err.vv:6:5: error: unwrapped optional cannot be compared in an infix expression
|
||||||
|
4 |
|
||||||
|
5 | fn main(){
|
||||||
|
6 | if foo() > foo() {}
|
||||||
|
| ~~~~~~~~~~~~~
|
||||||
|
7 | }
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn foo() ?int{
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
if foo() > foo() {}
|
||||||
|
}
|
Loading…
Reference in New Issue