Skip to content

Commit

Permalink
Revert ocaml-ppx#128 and reapply the original fix from ocaml-ppx#126
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Nov 7, 2020
1 parent 811dbcb commit ee12efb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ppx_deriving_yojson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ let ser_str_of_record ~loc varname labels =
| None ->
[%expr [%e result] :: fields]
| Some default ->
[%expr if Pervasives.(=) [%e field] [%e default] then fields else [%e result] :: fields])
[%expr if [%e field] = [%e default] then fields else [%e result] :: fields])
in
let assoc =
List.fold_left
Expand Down
16 changes: 14 additions & 2 deletions src/ppx_deriving_yojson_runtime.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include module type of Ppx_deriving_runtime

type 'a error_or = ('a, string) Result.result

val ( >>= ) : 'a error_or -> ('a -> 'b error_or) -> 'b error_or
Expand All @@ -10,3 +8,17 @@ val map_bind : ('a -> 'b error_or) -> 'b list -> 'a list -> 'b list error_or
computes it tail-recursively so that large list lengths don't
cause a stack overflow *)
val safe_map : ('a -> 'b) -> 'a list -> 'b list

val ( = ) : 'a -> 'a -> bool (* NOTE: Used for [@default ...] *)
module List : (module type of List)
module String : (module type of String)
module Bytes : (module type of Bytes)
module Int32 : (module type of Int32)
module Int64 : (module type of Int64)
module Nativeint : (module type of Nativeint)
module Array : (module type of Array)
module Result : sig
type ('a, 'b) result = ('a, 'b) Result.result =
| Ok of 'a
| Error of 'b
end
4 changes: 3 additions & 1 deletion src_test/test_ppx_yojson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,13 @@ let test_equality_redefined ctxt =
module Pervasives = struct
let (=) : int -> int -> bool = fun a b -> a = b
let _ = 1 = 1 (* just dummy usage of `=` to suppress compiler warning *)

let never_gonna_be_in_pervasives = None
end
let (=) : int -> int -> bool = fun a b -> a = b
let _ = 1 = 1 (* just dummy usage of `=` to suppress compiler warning *)

type t = {field : int option [@default None]} [@@deriving to_yojson]
type t = {field : int option [@default Pervasives.never_gonna_be_in_pervasives]} [@@deriving to_yojson]
let x = {field = Some 42}
end
in
Expand Down

0 comments on commit ee12efb

Please sign in to comment.