Skip to content

Typechecking issue with GADTs under or-patterns #325

@mbouaziz

Description

@mbouaziz

As mentioned in an OCaml PR, this code

type _ t = A : unit t | B : bool t

let f : type a. a t -> int =
  fun x -> match x with A | B -> 0

is instrumented as

let f : type a. a t -> int =
  fun x ->
    ___bisect_visit___ 2;
    (match x with
     | A|B as ___bisect_matched_value___ ->
         ((((match ___bisect_matched_value___ with
             | A -> (___bisect_visit___ 0; ())
             | B -> (___bisect_visit___ 1; ())
             | _ -> ()))
          [@ocaml.warning "-4-8-9-11-26-27-28"]);
          0))

rejected by the typechecker:

File "bin/main.ml", line 4, characters 28-29:
4 |   fun x -> match x with A | B -> 0
                                ^
Error: This pattern matches values of type bool t
       but a pattern was expected which matches values of type unit t
       Type bool is not compatible with type unit 

Waiting for it to be fixed in OCaml side, maybe the instrumentation could be changed to avoid using as?

let ___bisect_matched_value___ = x in
match x with ...

I don't know how that'd interact with nested or-patterns though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions