-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve our ability to override default parameters #11704
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
cdfa4b9
to
f0c909c
Compare
(this is a blocker for #11671) |
I think we want to go the other way: make default arguments inline (and hence final). Without that step we won't be able to get any of the other desired improvements of default arguments. So, is this change really necessary? |
It's necessary to get the scala.js tests to pass with #11671. This change improves compatibility with Scala 2 in general but does not change anything fundamentally, we already allow overrides for default parameters, this change just avoid seemingly arbitrary situations where this fails with a puzzling error message. So getting this change in won't have any impact on our future plans with default parameters. |
Also, independent of overrides, this change is good because it avoids breaking unnecessary breaks to binary compatibility, right now: class A {
def foo(param: X = new Y): X = param
} will generate a default getter whose return type is |
This comment has been minimized.
This comment has been minimized.
f0c909c
to
d584954
Compare
- Replace rhsType/widenRhs by typedAheadRhs/rhsType to avoid computing rhsProto twice - Rename rhsProto to defaultParamType and move the wildcard handling to rhsType (this will be useful in the next commit)
Don't just use the type of the rhs of the default getter as its inferred type, this can be more precise than the type of the corresponding parameter and prevent seemingly valid overrides.
d584954
to
fc34c1a
Compare
This is needed to compile geny in the community build which does: def count(f: A => Boolean = ((_: Any) => true)) This happened to work before the previous commit because the inferred type of the getter was `Any => Boolean`. Crucially, we can only disable variance checking for default getters whose result type matches the parameter type of the method, see default-getter-variance.scala for a detailed justification of why this is safe. This fixes lets us get rid of an unjustified usage of `@uncheckedVariance` when desugaring case classes.
fc34c1a
to
5b46ac2
Compare
This is now green after fixing some community build issues. |
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.
LGTM
It looks like this bug got fixed in scala#11704!
It looks like this bug got fixed in scala#11704!
Don't just use the type of the rhs of the default getter as its inferred
type, this can be more precise than the type of the corresponding
parameter and prevent seemingly valid overrides.