Skip to content

Commit

Permalink
fix(engine/import-thir): fix leaking errors
Browse files Browse the repository at this point in the history
The `capture` function of `diagnostics.ml` was baldy implemented.
Seems like in the expression `(f (), g ())` OCaml first runs `g` and
then `f`!

I'm using a state to capture errors, and using `(f (), !state)`, I was
ignoring the side effects of `f`, which is... the only point of that
`capture` function.
  • Loading branch information
W95Psp committed Jan 30, 2024
1 parent bd6c328 commit b3dcb1e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion engine/lib/diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ end = struct

let capture (type a) (f : unit -> a) : a * t list =
let previous_state = !state in
let result = (f (), !state) in
state := [];
let result =
let x = f () in
(x, !state)
in
state := previous_state;
result
end
Expand Down

0 comments on commit b3dcb1e

Please sign in to comment.