Skip to content

Commit ee12efb

Browse files
committed
Revert #128 and reapply the original fix from #126
1 parent 811dbcb commit ee12efb

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/ppx_deriving_yojson.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ let ser_str_of_record ~loc varname labels =
321321
| None ->
322322
[%expr [%e result] :: fields]
323323
| Some default ->
324-
[%expr if Pervasives.(=) [%e field] [%e default] then fields else [%e result] :: fields])
324+
[%expr if [%e field] = [%e default] then fields else [%e result] :: fields])
325325
in
326326
let assoc =
327327
List.fold_left

src/ppx_deriving_yojson_runtime.mli

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include module type of Ppx_deriving_runtime
2-
31
type 'a error_or = ('a, string) Result.result
42

53
val ( >>= ) : 'a error_or -> ('a -> 'b error_or) -> 'b error_or
@@ -10,3 +8,17 @@ val map_bind : ('a -> 'b error_or) -> 'b list -> 'a list -> 'b list error_or
108
computes it tail-recursively so that large list lengths don't
119
cause a stack overflow *)
1210
val safe_map : ('a -> 'b) -> 'a list -> 'b list
11+
12+
val ( = ) : 'a -> 'a -> bool (* NOTE: Used for [@default ...] *)
13+
module List : (module type of List)
14+
module String : (module type of String)
15+
module Bytes : (module type of Bytes)
16+
module Int32 : (module type of Int32)
17+
module Int64 : (module type of Int64)
18+
module Nativeint : (module type of Nativeint)
19+
module Array : (module type of Array)
20+
module Result : sig
21+
type ('a, 'b) result = ('a, 'b) Result.result =
22+
| Ok of 'a
23+
| Error of 'b
24+
end

src_test/test_ppx_yojson.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,13 @@ let test_equality_redefined ctxt =
510510
module Pervasives = struct
511511
let (=) : int -> int -> bool = fun a b -> a = b
512512
let _ = 1 = 1 (* just dummy usage of `=` to suppress compiler warning *)
513+
514+
let never_gonna_be_in_pervasives = None
513515
end
514516
let (=) : int -> int -> bool = fun a b -> a = b
515517
let _ = 1 = 1 (* just dummy usage of `=` to suppress compiler warning *)
516518

517-
type t = {field : int option [@default None]} [@@deriving to_yojson]
519+
type t = {field : int option [@default Pervasives.never_gonna_be_in_pervasives]} [@@deriving to_yojson]
518520
let x = {field = Some 42}
519521
end
520522
in

0 commit comments

Comments
 (0)