Skip to content

Commit

Permalink
fix: do not leak let bind and force Stdlib usage (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries authored Jul 3, 2024
1 parent 57ba698 commit 89b60d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions derive/de.ml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ module Record_deserializer = struct
| `required ->
[%expr
let* [%p field_pat] =
Option.to_result ~none:(`Msg [%e missing_msg]) ![%e field_var]
Stdlib.Option.to_result
~none:(`Msg [%e missing_msg])
![%e field_var]
in
[%e last]]
| `optional ->
Expand Down Expand Up @@ -791,13 +793,13 @@ let gen_deserialize_impl ~ctxt type_decl =
in
[%stri
let [%p deserializer_name] =
let ( let* ) = Result.bind in
let ( let* ) = Stdlib.Result.bind in
let _ = ( let* ) in
Serde.De.(fun ctx -> [%e body])]

let generate_impl ~ctxt (_rec_flag, type_declarations) =
let loc = loc ~ctxt in
[ [%stri open! Serde]; [%stri let ( let* ) = Result.bind] ]
[ [%stri open! Serde] ]
@ List.map (gen_deserialize_impl ~ctxt) type_declarations

let impl_generator = Deriving.Generator.V2.make_noarg generate_impl
Expand Down
9 changes: 6 additions & 3 deletions derive/ser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,15 @@ let gen_serialize_impl ~ctxt type_decl =
let serializer_name =
"serialize_" ^ typename |> var ~ctxt |> Ast.ppat_var ~loc
in
[%stri let [%p serializer_name] = Serde.Ser.(fun t ctx -> [%e body])]
[%stri
let [%p serializer_name] =
let ( let* ) = Stdlib.Result.bind in
let _ = ( let* ) in
Serde.Ser.(fun t ctx -> [%e body])]

let generate_impl ~ctxt (_rec_flag, type_declarations) =
let loc = loc ~ctxt in
[ [%stri let ( let* ) = Result.bind] ]
@ List.map (gen_serialize_impl ~ctxt) type_declarations
List.map (gen_serialize_impl ~ctxt) type_declarations

let impl_generator = Deriving.Generator.V2.make_noarg generate_impl

Expand Down

0 comments on commit 89b60d6

Please sign in to comment.