Compilation error while matching Typedtree

I’m trying to match a part of typed tree version 3.12.1 but got a type error. It says that tpat_value_argument was expected and I gave him a pattern for type _ pattern_data.
But tpat_value_argument is an alias for general_pattern which is an alias for pattern_data. I’m not sure what causes it, probably, it is very simple question, and highly likely very stupid one :slight_smile:

Any ideas? The MVP for 3.12.1 is below

#use "topfind";;
#require "compiler-libs.common";;
module _ = struct
  open Typedtree

  let () = assert (Sys.ocaml_version = "4.12.1")

  type nonrec 'a pattern_data = 'a Typedtree.pattern_data = {
    pat_desc : 'a;
    pat_loc : Location.t;
    pat_extra : (Typedtree.pat_extra * Location.t * Typedtree.attributes) list;
    pat_type : Types.type_expr;
    pat_env : Env.t;
    pat_attributes : Typedtree.attributes;
  };;

  type nonrec tpat_value_argument = private
    Typedtree.value Typedtree.general_pattern
  ;;
  type nonrec 'k general_pattern =
    'k pattern_desc pattern_data  ;;

  let xxxx = function
    | Tpat_value {pat_desc} -> true
  ;;
(*
58 |     | Tpat_value {pat_desc} -> true
                      ^^^^^^^^^^
Error: This pattern matches values of type
         'a pattern_data = 'a Typedtree.pattern_data
       but a pattern was expected which matches values of type
         Typedtree.tpat_value_argument
*)
end;;

The type tpat_value_argument is a private abbreviation. You are missing a coercion.

It looks like this piece of code compiles

let xxxx = function
  | Tpat_value x ->
      match (x :> (Typedtree.value Typedtree.general_pattern)) with
      | _ -> true

Any chance to make this coercion shorter? For example, move it from expression insde pattern…

You can use Typedtree.pattern as an alias to to value general_pattern.