Skip to content

Commit

Permalink
Restrict type for [%eq: unit] and [%ord: unit]
Browse files Browse the repository at this point in the history
Otherwise the following is possible:

    # [%eq: unit] 2 3;;
    - : bool = true

and

    # [%ord: unit] 2 3;;
    - : int = 0

See #115 for a similar, solved, problem.
  • Loading branch information
emillon authored and whitequark committed Jan 26, 2018
1 parent 91d4593 commit 84c980f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src_plugins/ppx_deriving_eq.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ and expr_of_typ quoter typ =
let builtin = not (attr_nobuiltin typ.ptyp_attributes) in
begin match builtin, typ with
| true, [%type: unit] ->
[%expr fun _ _ -> true]
[%expr fun (_:unit) (_:unit) -> true]
| true, ([%type: int] | [%type: int32] | [%type: Int32.t] |
[%type: int64] | [%type: Int64.t] | [%type: nativeint] |
[%type: Nativeint.t] | [%type: float] | [%type: bool] |
Expand Down
4 changes: 3 additions & 1 deletion src_plugins/ppx_deriving_ord.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ and expr_of_typ quoter typ =
| { ptyp_desc = Ptyp_constr _ } ->
let builtin = not (attr_nobuiltin typ.ptyp_attributes) in
begin match builtin, typ with
| true, ([%type: _] | [%type: unit]) ->
| true, [%type: _] ->
[%expr fun _ _ -> 0]
| true, [%type: unit] ->
[%expr fun (_:unit) (_:unit) -> 0]
| true, ([%type: int] | [%type: int32] | [%type: Int32.t]
| [%type: int64] | [%type: Int64.t] | [%type: nativeint]
| [%type: Nativeint.t] | [%type: float] | [%type: bool]
Expand Down

0 comments on commit 84c980f

Please sign in to comment.