You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand the underlying problem is the one mentioned in the related issue, but would it make sense to fix this issue at the parsing level? I was playing with it, and unrolling fun_binding into let_binding_body and moving the constraint to the left-hand side of the binding would fix it. I don't really have any context here, so I'm sorry if that's too hacky, but I was browsing through and thought I'd mention as it'd be a tiny change.
The problem is that for some other let-bindings of the form "let x : t = e", the current interpretation as "let x = (e : t)" is the right one, it allows you to type-check more programs (this also depends on whether the binding is recursive; see #7389 for more discussion). In -principal mode, type-checking is made more robust by inferring less from the annotation, but then it actually requires more annotations.
Fixed by commit fd0dc6a.
The type annotation is duplicated on the pattern in the first case (it is also left on the expression for propagation on both sides).
The only cases where propagation does not occur on the expression side are the second one (annotation on a parenthesized pattern), and the 3rd case (polymorphic type with variables limited to the annotations). The "let rec f : type a. ... = ..." already propagates on both sides.
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> =
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>) =
val f : unit -> < m : 'a. 'a -> 'a > =
or if you add an unused polymorphic variable:
let rec f : 'b. unit -> < m: 'a. 'a -> 'a> =
val f : unit -> < m : 'a. 'a -> 'a > =
or if you turn on
-principal
:#principal true;;
let rec f : unit -> < m: 'a. 'a -> 'a> =
val f : unit -> < m : 'a. 'a -> 'a > =
The text was updated successfully, but these errors were encountered: