fix optional-presence comparison

This commit is contained in:
2026-07-20 15:28:00 +02:00
parent deab47e75e
commit ec36b6b861
5 changed files with 138 additions and 17 deletions
+19
View File
@@ -561,6 +561,25 @@ lower_compound_expr :: proc(state: ^State, expr_id: hir.Expr_Id) -> ir.Instructi
diagnostic=source.INVALID_DIAGNOSTIC,
})
case .Eq, .Ne, .Lt, .Le, .Gt, .Ge:
left_expr := state.hir_module.exprs[expr.left]
right_expr := state.hir_module.exprs[expr.right]
if left_expr.kind == .None || right_expr.kind == .None {
optional_expr := expr.right if left_expr.kind == .None else expr.left
optional := lower_nested_expr(state, optional_expr)
present := append_instruction(state, ir.Instruction{
op=.Optional_Is_Some, span=expr.span, type=types.BOOL,
target=ir.INVALID_REF, a=optional, b=ir.INVALID_INSTRUCTION,
diagnostic=source.INVALID_DIAGNOSTIC,
})
if expr.kind == .Ne {
return present
}
return append_instruction(state, ir.Instruction{
op=.Not, span=expr.span, type=types.BOOL,
target=ir.INVALID_REF, a=present, b=ir.INVALID_INSTRUCTION,
diagnostic=source.INVALID_DIAGNOSTIC,
})
}
left := lower_nested_expr(state, expr.left)
right := lower_nested_expr(state, expr.right)
predicate := ir.Compare_Predicate.Eq