-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1430: Better error messages for type errors involving type variables #1434
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
Conversation
The class Inv[T](x: T)
object Test {
val x: Inv[String] = new Inv(new Inv(1))
} error: type mismatch:
found : Inv[T]
required: String
val x: Inv[String] = new Inv(new Inv(1))
^ |
@smarter The |
|
This has evolved into a rather big refactoring affecting many of the error messages in the compiler. We can now systematically explain ambiguous names and type variables as appendices to error messages. errmsgs.check gives a taste. |
} | ||
} | ||
|
||
/** The d string interpolator works like the i string interpolator, but marks nonsensical errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now called em and not d
This is neat, but the disambiguation system should have a special case for aliases, consider:
Contrast with
|
(We also need to do something about printing "object Predef$" instead of "object Predef" but that's a separate issue) |
We should also look into eliding prefixes (like
|
Probably over-thinking this but instead of |
We could also optionally use different colors for disambiguation :) |
@smarter I am open to other ways to indicate variants (color or subscripts are both is nice!) but we should know it works on all terminals. |
When issuing a type mismatch error, avoid mentioning polyparams in the current constraint set and their associated typevars. Mention instead the bound that caused the constrained to become unsatisfiable (if that bound is unique, i.e. the parameter appears co- or contravariantly in the type).
Interpolating typevars that appear co- or contra-variantly in a type is a cleanup measure - it helps keep the constraint set small. However, if there are uneported errors, some of these errors might report on unsatisfiable constraints for these type variables. In that case, instantiating the type variables risks being confusing.
Remove debug info from error message.
Roll `sm` and `i` into one interpolator (also called `i`) Evolve `d` to `em` interpolator (for error messages) New interpolator `ex` with more explanations, replaces disambiguation.
Needs to read several input lines at once. Enables repl test of new error messages.
Normal show will propagate the excpetions. Previously, exceptions were filtered in both cases, which was redundant. Also, it's good to have a way to show things that does not mask exceptions, if only to debug problems in show itself.
Don't disambiguate in situations like Predef.String vs java.lang.String where one Symbol is an alias of another with the same name. Also, fix reviewer comments wrt comments and unused defs.
This was already disabled when printing types. Now is also disabled when printing fully qualified names.
... when printing using RefinedPrinter. PlainPrinter will still show them.
The previous fix was too drastic, as it would also have omitted scala, Prefef and other "unqualified owner types" from full names. We now omit only "empty prefixes", i.e. roots, anonymous classes and repl qualifiers.
546c92c
to
3a2efae
Compare
Rebased to master to avoid merge conflicts. Any objections to merge this now? Otherwise this PR will be in perennial conflict with everything else that's likely to be committed. |
/rebuild |
LGTM assuming the tests pass |
It looks like the CI has stalled on all PRs? |
/rebuild |
I amended the last commit to force the CI to run again, seems OK now. |
Two fixes: (1) Report bounds instead of the variables themselves. (2) Avoid interpolation if there are unreported errors. Also, clean up of error message mentioned in #1424.
Review by @smarter.