Skip to content

Commit

Permalink
Fix lazy evaluation of and/or in the OCaml backend (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr authored Jan 10, 2025
2 parents 66c5df5 + 05d177d commit 0422f5c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/lcalc/to_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ let rec format_expr (ctx : decl_ctx) (fmt : Format.formatter) (e : 'm expr) :
Format.fprintf fmt
"@[<hov 2> if@ @[<hov 2>%a@]@ then@ @[<hov 2>%a@]@ else@ @[<hov 2>%a@]@]"
format_with_parens cond format_with_parens etrue format_with_parens efalse
| EAppOp { op = ((And | Or) as op), _; args = [e1; e2]; _ } ->
Format.fprintf fmt "@[<hov 2>%a %s@ %a@]" format_with_parens e1
(if op = And then "&&" else "||")
format_with_parens e2
| EAppOp { op = op, pos; args; _ } ->
Format.fprintf fmt "@[<hov 2>%s@ %t%a@]" (Operator.name op)
(fun ppf ->
Expand Down
2 changes: 1 addition & 1 deletion tests/name_resolution/good/conflicts-module.catala_en
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end

let closure_scoppe__2 : Obj.t -> bool -> integer -> bool =
fun (_: Obj.t) (acc: bool) (x: integer) ->
o_and acc (o_gt_int_int x (integer_of_string "2"))
acc && (o_gt_int_int x (integer_of_string "2"))

let closure_scoppe (_: Closure_scoppe_in.t) : Closure_scoppe.t =
let scoppe: bool =
Expand Down
2 changes: 1 addition & 1 deletion tests/name_resolution/good/let_in2.catala_en
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let s (s_in: S_in.t) : S.t =
(match
(Eoption.ESome (let a__2 : bool = false
in
(let a__3 : bool = (o_or a__2 true) in
(let a__3 : bool = (a__2 || true) in
a__3)))
with
| Eoption.ENone _ -> (raise
Expand Down

0 comments on commit 0422f5c

Please sign in to comment.