Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
native: fix handling default record field value
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp committed Apr 3, 2024
1 parent 5908fdf commit f026bee
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions native/ppx_deriving_json_native.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,22 @@ module Of_json = struct
let key =
Option.get_or ~default:ld.pld_name (ld_attr_json_key ld)
in
let default = ld_attr_json_default ld in
( map_loc lident ld.pld_name,
[%expr
match Stdlib.( ! ) [%e ename ld.pld_name] with
| Stdlib.Option.Some v -> v
| Stdlib.Option.None ->
Ppx_deriving_json_runtime.of_json_error
[%e
estring ~loc:key.loc
(sprintf "missing field %S" key.txt)]] ))
[%e
match default with
| Some default -> default
| None ->
[%expr
Ppx_deriving_json_runtime.of_json_error
[%e
estring ~loc:key.loc
(sprintf "missing field %S" key.txt)]]]]
))
in
pexp_record ~loc fields None
in
Expand Down

0 comments on commit f026bee

Please sign in to comment.