Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006308OCamlOCaml typingpublic2014-01-27 17:132014-03-18 15:41
Reporterfrisch 
Assigned Tofrisch 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.02.0+dev 
Summary0006308: Error message not properly located (or phrased) with or-pattern
DescriptionConsider 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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0010848)
frisch (developer)
2014-01-27 17:24

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).
(0010849)
frisch (developer)
2014-01-27 17:29

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
(0010850)
lpw25 (developer)
2014-01-27 19:21

Does that message still make sense if there are more than two branches to the or-pattern?

For example:

    type 'a t = {y : bool; x: 'a};;

    function {y = true; _} | {x=Some a; _} | {x=a; _} -> ();;
(0010851)
frisch (developer)
2014-01-28 09:25

# function {y = true; _} | {x=Some a; _} | {x=a; _} -> ();;
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


This seems decent to me.

- Issue History
Date Modified Username Field Change
2014-01-27 17:13 frisch New Issue
2014-01-27 17:24 frisch Note Added: 0010848
2014-01-27 17:29 frisch Note Added: 0010849
2014-01-27 19:21 lpw25 Note Added: 0010850
2014-01-28 09:25 frisch Note Added: 0010851
2014-03-18 15:41 frisch Status new => resolved
2014-03-18 15:41 frisch Fixed in Version => 4.02.0+dev
2014-03-18 15:41 frisch Resolution open => fixed
2014-03-18 15:41 frisch Assigned To => frisch


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker