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

Issue with type information flowing through a variant pattern #6235

vicuna opened this issue Nov 12, 2013 · 2 comments


None yet
2 participants
Copy link

commented Nov 12, 2013

Original bug ID: 6235
Reporter: @alainfrisch
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:25:15Z)
Resolution: fixed
Priority: normal
Severity: minor
Fixed in version: 4.01.1+dev
Category: typing
Monitored by: @bobzhang @hcarty

Bug description

As reported by Bob Zhang on the caml-list:

type t = { loc : string; }
type v = { loc : string; x : int; }
type u = [ `Key of t ]
let f (u : u) = match u with `Key {loc} -> loc;;
Error: This pattern matches values of type [? `Key of v ]
       but a pattern was expected which matches values of type u
       Types for tag `Key are incompatible

This is surprising, because:

 let f (u : u) = match u with `Key loc -> loc.loc

works fine.


This comment has been minimized.

Copy link

commented Nov 12, 2013


This comment has been minimized.

Copy link

commented Nov 13, 2013

Comment author: @garrigue

Fixed in 4.01 and trunk, revisions 14284 and 14285.

In trunk, also made principal mode a bit more strict, by keeping different branches of a pattern-matching independent when typing patterns.
I.e., assuming the same type definitions, the following function is refused in principal mode (but accepted in standard mode).

let f = function
| (_ : u) when false -> ""
|`Key {loc} -> loc

Rationale for refusing this: changing the order of branches breaks the typing.

@vicuna vicuna closed this Dec 11, 2015

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.