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

More context for unbound type parameter error #1998

Conversation

Projects
None yet
2 participants
@Octachron
Copy link
Contributor

commented Aug 20, 2018

This PR updates the "unbound type parameter" error to make it more similar to the two other "unbound type variable" errors in the compiler. For instance, the error message for

type 'a t = A of 'at

goes from

Error: Unbound type parameter 'at

to

Error: The type variable 'at is unbound in this type declaration.
Hint: Did you mean 'a?

This error message not only gives more context to the errror, it is also closer to the message for classes
(raised in Typeclass)

class c = object method m:'a -> 'a = fun x -> x end;;

Error: Some type variables are unbound in this type:
class c : object method m : 'a -> 'a end
The method m has type 'a -> 'a where 'a is unbound

and the late-stage error message for unbound type variables in a type declaration (raised in Typedecl):

type 'a t = A of ([< 'a] as 'at)

Error: A type variable is unbound in this type declaration.
In case A of ([< `a ] as 'at) the variable 'at is unbound

The spellchecker hints has been added since it was kind of suggested by a comment
and I removed an unused function that raised this error message due to the narrowing of this
error message.

@@ -28,7 +28,6 @@ val transl_simple_type_delayed:
val transl_type_scheme:
Env.t -> Parsetree.core_type -> Typedtree.core_type
val reset_type_variables: unit -> unit
val type_variable: Location.t -> string -> type_expr

This comment has been minimized.

Copy link
@gasche

gasche Aug 21, 2018

Member

Why are you removing this function? It looks like it could be convenient for compiler-libs user. Is it doing the wrong thing? (If I understand the patch correctly, the Unbound_type_variable error that is caught in report is raised by a different site?)

This comment has been minimized.

Copy link
@Octachron

Octachron Aug 21, 2018

Author Contributor

The Unbound_type_variable error caught by report is raised by transl_simple_type but only if the fixed argument is true. Currently, the only calls to Typetexp.transl_simple_type with fixed=true happen in Typedecl, and thus the error only happens when typechecking type declaration. It seemed thus consistent to both specialize the error message provided by Unbound_type_variable with this context in mind and remove the ability to (accidentally) raise Unbound_type_variable out of this context. But you are right, this function should probably stay for the sake of compiler-libs. (Even if I am not sure how convenient this function really is).

This comment has been minimized.

Copy link
@Octachron

Octachron Aug 21, 2018

Author Contributor

I reverted this deletion.

@gasche

gasche approved these changes Aug 21, 2018

@gasche

This comment has been minimized.

Copy link
Member

commented Aug 21, 2018

Checking 3b3f641d37bc44ea37a2aa08d61af4a31d8f1e5e: testsuite/tests/typing-misc/ocamltests
./testsuite/tests/typing-misc/ocamltests:25.19: [missing-lf] missing linefeed at EOF

@Octachron Octachron force-pushed the Octachron:typetexp_spellchecking_hints_for_unbound_type_parameters branch from 61199ed to c248a47 Aug 22, 2018

@Octachron

This comment has been minimized.

Copy link
Contributor Author

commented Aug 22, 2018

I have fixed the missing newline while updating Changes.

@gasche gasche merged commit 985061a into ocaml:trunk Aug 22, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
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.