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
Original bug ID: 6308 Reporter:@alainfrisch Assigned to:@alainfrisch Status: closed (set by @xavierleroy on 2015-12-11T18:25:52Z) Resolution: fixed Priority: normal Severity: minor Fixed in version: 4.02.0+dev Category: typing Monitored by:@gasche
Bug description
Consider the following error message:
type 'a t = {x: 'a}
function {x=a} | {x=(a,_)} -> ();;
^^^^^^^^^^^^^^^^^
Error: This pattern matches values of type 'a * 'b
but a pattern was expected which matches values of type 'a
The type variable 'a occurs inside 'a * 'b
The location of the error is the whole or-pattern, which is not coherent with its text.
The text was updated successfully, but these errors were encountered:
It all happens in the enter_orpat_variables function (in typecore.ml). One must decide between using l2 instead of loc for the Pattern_type_clash error (and calling "unify env t2 t1" instead of "unify env t1 t2"), or using a different error which clearly indicates that the problem is related to the or-pattern (and gives the variable name).
I've committed a fix using a different error message, commit 14421 on trunk. If anyone want to argue in favor of keeping the old error with a different location (or suggest a better wording of the new message), don't hesitate!
# type 'a t = {x: 'a};;
type 'a t = { x : 'a; }
# function {x=Some a} | {x=a} -> ();;
^^^^^^^^^^^^^^^^^^
Error: The variable a on the left-hand side of this or-pattern has type 'a
but on the right-hand side it has type 'a option
The type variable 'a occurs inside 'a option
Error: Variable a must occur on both sides of this | pattern
If you meant:
# function {y = a; _} | {x=Some a; _} | {x=a; _} -> ();;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The variable a on the left-hand side of this or-pattern has type
bool but on the right-hand side it has type bool option
# type t = { x : int; y : string; z : bool; };;
# function {x = a; _} | {y = a; _} | {z = a; _} -> ();;
^^^^^^^^^^^^^^^^^^^^^^^
Error: The variable a on the left-hand side of this or-pattern has type
int but on the right-hand side it has type string
Original bug ID: 6308
Reporter: @alainfrisch
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2015-12-11T18:25:52Z)
Resolution: fixed
Priority: normal
Severity: minor
Fixed in version: 4.02.0+dev
Category: typing
Monitored by: @gasche
Bug description
Consider the following error message:
The location of the error is the whole or-pattern, which is not coherent with its text.
The text was updated successfully, but these errors were encountered: