-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Disallow overriding val parameters #16096
Merged
Merged
Commits on Sep 25, 2022
-
Disallow overriding val parameters
We disallow overriding of val parameters, which fixes the soundness problem discovered in scala#16092. There is one exception: If a val parameter is overridden by another val parameter that can be shown to always have the same value (in the sense established by Paramforwarding.inheritedAccessor). This exception is needed to make a not-so-uncommon pattern of case class inheritance go through. Example: abstract class A(val x: Int) case class B(override val x: Int) extends A(x) case class C(override val x: Int) extends A(x) case object D extends A(0) Here, the `override val`s are necessary since case class parameters are always vals, so they do override the val in class A. It should be noted that the override val generates a second field, so this not a very efficient representation. A better design would be to use an abstract field in `A`: abstract class A { val x: Int } case class B(val x: Int) extends A case class C(val x: Int) extends A case object D extends A { val a = 0 } But that causes slightly more work for cases as in D. Which seems to be why the first pattern is sometimes used. It might be desirable to disallow the second pattern, but that would cause quite a bit of migration hassle since it requires synchronized changes at several places of a class hierarchy.
Configuration menu - View commit details
-
Copy full SHA for b5f307d - Browse repository at this point
Copy the full SHA b5f307dView commit details -
Reject overrides only with -source future
Currently, the following CB projects have illegal overrides of val parameters - spire - scalaz - specs2 - akka I checked the spire issue and its seems to require a non-trivial refactoring to avoid the problem. More than I could achieve, given that I know nothing of spire. In light of this I think we can enforce the restriction only under -source future and make it a deprecation warning for now.
Configuration menu - View commit details
-
Copy full SHA for 34d87db - Browse repository at this point
Copy the full SHA 34d87dbView commit details -
Configuration menu - View commit details
-
Copy full SHA for b1856e7 - Browse repository at this point
Copy the full SHA b1856e7View commit details -
Configuration menu - View commit details
-
Copy full SHA for d1862de - Browse repository at this point
Copy the full SHA d1862deView commit details
Commits on Sep 26, 2022
-
Configuration menu - View commit details
-
Copy full SHA for dd85d57 - Browse repository at this point
Copy the full SHA dd85d57View commit details -
Temporarily, always report an error instead of a deprecation warning to verify that projects compile. This will be reverted in the next commit.
Configuration menu - View commit details
-
Copy full SHA for a07d9e6 - Browse repository at this point
Copy the full SHA a07d9e6View commit details -
Configuration menu - View commit details
-
Copy full SHA for f43e98e - Browse repository at this point
Copy the full SHA f43e98eView commit details -
Configuration menu - View commit details
-
Copy full SHA for fb75d96 - Browse repository at this point
Copy the full SHA fb75d96View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.