-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4720 and #4721: account for type inference being too smart #4946
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
Fix #4720 and #4721: account for type inference being too smart #4946
Conversation
Fix regression in eeb5965. A type variable can already be solved in addToConstraint, so don't assume it is unsolved (hence its constraint entry is a TypeBounds) when first processing it. Fix scala#4720.
5a081ae
to
d84922b
Compare
Be more defensive to handle other issues such as scala#4720 (comment). Code that needs to access the actual entry can call `entry` or `contains` instead.
@@ -60,7 +60,7 @@ abstract class Constraint extends Showable { | |||
* are not contained in the return bounds. | |||
* @pre `param` is not part of the constraint domain. | |||
*/ |
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.
Is this comment still correct?
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.
I can't make sense of "@pre param
is not part of the constraint domain." if that's a precondition. What's the "constraint domain"?
Otherwise, I suspect yes.
Poly params that are known to be smaller or greater than
param
are not contained in the return bounds.
IIUC, this suggests that in [Y<:String, Z>:Int, W>:Z<:Y]
, nonParamBounds(Y)
and nonParamBounds(Z)
don't include W
. But nonParamBounds(W)
should mention Z
and Y
, so it might never have been accurate.
EDIT: my patch doesn't affect it, and neither does yours; this comment means, concretely, that we only account for boundsMap
but not lowerMap
or upperMap
. How information is partitioned between those map is another matter entirely (and might be affected by your patch).
This isn't great, if there really are cases where this message is the only one, it's likely to be very confusing to users. |
That's what I hoped to learn from you or @odersky. But I think that can't happen and I should drop the last commit. This is just inference, and we must check bounds also for type arguments written by users, or we have bigger issues, and hopefully that's checked by the same code. This is done by calling So I'll drop last commit. The resulting error is better, but it's designed for types written by the user, not synthesized by inference:
Otherwise, I can propagate more info out of Maybe I can just detect if the type argument tree was inferred? With |
A synthetic tree can contain a user written tree. Use pos.isZeroExtent instead |
72d7bc4
to
69957bb
Compare
Fix #4720 and #4721: account for @smarter type inference. Some type arguments can be solved right away by looking at their bounds alone, so handle them gracefully.
#4720 was introduced by eeb5965, #4721 was earlier.