Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@equal] annotation not working #214

Closed
fangyi-zhou opened this issue Feb 3, 2020 · 1 comment
Closed

[@equal] annotation not working #214

fangyi-zhou opened this issue Feb 3, 2020 · 1 comment

Comments

@fangyi-zhou
Copy link

$ cat main.ml
type t
  = A of int * int [@equal fun (_, a) (_, b) -> Int.(a = b)]
  [@@deriving eq]

let a1 = A (1, 2)
let a2 = A (2, 2)
let () =
  Printf.printf "a1 and a2 are %s" (if equal a1 a2 then "equal" else "not equal")
$ ocamlfind ocamlopt -ppx '`ocamlfind query ppx_deriving`/ppx_deriving `ocamlfind query ppx_deriving`/eq/ppx_deriving_eq.cma' -dsource -c main.ml
type t =
  | A of int * int [@equal fun (_, a) -> fun (_, b) -> let open Int in a = b]
[@@deriving eq]
let rec (equal : t -> t -> Ppx_deriving_runtime.bool) =
  ((let open! ((Ppx_deriving_runtime)[@ocaml.warning "-A"]) in
      fun lhs ->
        fun rhs ->
          match (lhs, rhs) with
          | (A (lhs0, lhs1), A (rhs0, rhs1)) ->
              ((fun (a : int) -> fun b -> a = b) lhs0 rhs0) &&
                (((fun (a : int) -> fun b -> a = b)) lhs1 rhs1)
          | _ -> false)
  [@ocaml.warning "-A"])[@@ocaml.warning "-39"]
let a1 = A (1, 2)
let a2 = A (2, 2)
let () =
  Printf.printf "a1 and a2 are %s"
    (if equal a1 a2 then "equal" else "not equal")
File "main.ml", line 1, characters 0-85:
1 | type t
2 |   = A of int * int [@equal fun (_, a) (_, b) -> Int.(a = b)]
3 |   [@@deriving eq]
Error: Unbound module Ppx_deriving_runtime

I think the [@Equal] annotation is not taken care of inside the variant.

(I also find it difficult to debug the situation - I ran into the issue #150 when trying to get the AST)

@fangyi-zhou
Copy link
Author

fangyi-zhou commented Feb 3, 2020

I figured out this is similar to #209, but I was expecting this to work

type t
   = A of int * int [@equal fun (_, a) (_, b) -> Int.(a = b)]
   | B of string
   [@@deriving eq]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant