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

Confusing error message when mixing polymorphic variant and type variable name starting with a capital letter #7012

Closed
vicuna opened this issue Oct 9, 2015 · 5 comments
Assignees
Labels

Comments

@vicuna
Copy link

@vicuna vicuna commented Oct 9, 2015

Original bug ID: 7012
Reporter: @Octachron
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-02-16T14:14:47Z)
Resolution: fixed
Priority: low
Severity: minor
Version: 4.02.3
Fixed in version: 4.03.0+dev / +beta1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @gasche @hcarty

Bug description

The problem appears with

#type t = [ 'A_name | `Hi ]
Error: The type 'a is not a polymorphic variant type.

For some reasons, the type variable name 'A_name seems to be forgotten and replaced by the generic and confusing 'a.

Moreover, this happens only when the type variable name starts with a capital letter, more standard type variable names are not subject to this erasure:

type t = [ 'a_name | `Hi ] ;;

Error: The type 'a_name is not a polymorphic variant type

@vicuna
Copy link
Author

@vicuna vicuna commented Oct 9, 2015

Comment author: @Octachron

Correction:
The compiler simply forgets the name of type variable starting with a capital letter.

Compare

let f (x:'id_arg) = x;;

val f : 'id_arg -> 'id_arg =

with

let f (x:'Id_arg) = x;;

val f : 'a -> 'a =

@vicuna
Copy link
Author

@vicuna vicuna commented Oct 10, 2015

Comment author: @garrigue

Fixed in trunk at revision 16489.

Didn't know that variable names could start with a capital letter...

@vicuna
Copy link
Author

@vicuna vicuna commented Oct 10, 2015

Comment author: talex

Might be worth extending the error message in this case with a "- did you mean `A_name"?

@vicuna
Copy link
Author

@vicuna vicuna commented Oct 17, 2015

Comment author: @gasche

I extended the error message with a hint as you suggest.

Note that while

type t = [ 'Foo | 'Bar ]

(or any combination with a ' and a `)
will get you the hint, just writing

type t = [ 'Foo ]

is caught as a syntax error at an earlier stage, and does not benefit from the same treatment. We're thinking about general improvements on syntax error reporting, so I won't spend time on this error specifically.

@vicuna
Copy link
Author

@vicuna vicuna commented Oct 18, 2015

Comment author: talex

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants