Skip to content

Typing without -principal is broken in 4.11 and trunk #9759

@trefis

Description

@trefis

Noticed while adding support for 4.11 in merlin, reproducible with:

$ ./runtime/ocamlrun ./ocamlc -nostdlib -I stdlib -I utils -I parsing -I typing -principal -c ./typing/typedtree.ml
$ ./runtime/ocamlrun ./ocamlc -nostdlib -I stdlib -I utils -I parsing -I typing -c ./typing/typedtree.ml
File "./typing/typedtree.ml", lines 793-808, characters 17-22:
793 | .................match p.pat_desc with
794 |   | Tpat_var (id, s) -> (* note the ``Not_found'' case *)
795 |       {p with pat_desc =
796 |        try Tpat_var (alpha_var env id, s) with
797 |        | Not_found -> Tpat_any}
...
805 |   | d ->
806 |      let pat_desc =
807 |        shallow_map_pattern_desc { f = fun p -> alpha_pat env p } d in
808 |      {p with pat_desc}
Error: This expression has type k pattern_desc pattern_data
       but an expression was expected of type 'a 
       This instance of k is ambiguous:
       it would escape the scope of its equation

The code in question:

let rec alpha_pat
  : type k . _ -> k general_pattern -> k general_pattern
  = fun env p -> match p.pat_desc with
  | Tpat_var (id, s) -> (* note the ``Not_found'' case *)
      {p with pat_desc =
       try Tpat_var (alpha_var env id, s) with
       | Not_found -> Tpat_any}
  | Tpat_alias (p1, id, s) ->
      let new_p =  alpha_pat env p1 in
      begin try
        {p with pat_desc = Tpat_alias (new_p, alpha_var env id, s)}
      with
      | Not_found -> new_p
      end
  | d ->
     let pat_desc =
       shallow_map_pattern_desc { f = fun p -> alpha_pat env p } d in
     {p with pat_desc}

Given the error message, it looks like the type annotation on the function is ignored.
This doesn't appear to be due to #1132 (I confirm that the bug also exists before that PR).

It could also be that this is just an issue with the printing of the error, that the expected type is in fact not ignored but that the level handling is incorrect in some place(s).

Note: I'm going on vacation tonight, so I won't be able to look at this before the end of next week. Anyone else should feel free to have a look.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions