Skip to content

Inconsistent order when typing constraint patterns #7344

@vicuna

Description

@vicuna

Original bug ID: 7344
Reporter: @lpw25
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2017-03-15T01:56:44Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0
Target version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Fixed in version: 4.06.0 +dev/beta1/beta2/rc1
Category: typing
Related to: #7389
Monitored by: @gasche @hcarty

Bug description

The following code does not type-check:

let rec f : unit -> < m: 'a. 'a -> 'a> =

  fun () ->
    let x = f () in
    ignore (x#m 1);
    ignore (x#m "hello");
    assert false;;

Characters 117-124:
ignore (x#m "hello");
^^^^^^^
Error: This expression has type string but an expression was expected of type
int

but it does if you add parentheses:

let rec (f : unit -> < m: 'a. 'a -> 'a>) =

  fun () ->
    let x = f () in
    ignore (x#m 1);
    ignore (x#m "hello");
    assert false;;

val f : unit -> < m : 'a. 'a -> 'a > =

or if you add an unused polymorphic variable:

let rec f : 'b. unit -> < m: 'a. 'a -> 'a> =

  fun () ->
    let x = f () in
    ignore (x#m 1);
    ignore (x#m "hello");
    assert false;;

val f : unit -> < m : 'a. 'a -> 'a > =

or if you turn on -principal:

#principal true;;

let rec f : unit -> < m: 'a. 'a -> 'a> =

  fun () ->
    let x = f () in
    ignore (x#m 1);
    ignore (x#m "hello");
    assert false;;

val f : unit -> < m : 'a. 'a -> 'a > =

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions