-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5433: check that the implemented super-accessor is valid #5604
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5cebc76
Fix #5433: check that the implemented super-accessor is valid
smarter fc7c190
Avoid non-determinism in stdlib test by sorting files
smarter ce97789
Avoid super-calls leading to illegal superaccessors
smarter 8bad055
Make the illegal super accessor message a case class
smarter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<298..298> in i5433.scala | ||
class Fail cannot be defined due to a conflict between its parents when | ||
implementing a super-accessor for foo in trait C: | ||
|
||
1. One of its parent (trait C) contains a call super.foo in its body, | ||
and when a super-call in a trait is written without an explicit parent | ||
listed in brackets, it is implemented by a generated super-accessor in | ||
the class that extends this trait based on the linearization order of | ||
the class. | ||
2. Because B comes before C in the linearization | ||
order of Fail, and because B overrides foo, | ||
the super-accessor in Fail is implemented as a call to | ||
super[B].foo. | ||
3. However, | ||
X (the type of super[B].foo in Fail) | ||
is not a subtype of | ||
Y (the type of foo in trait C). | ||
Hence, the super-accessor that needs to be generated in Fail | ||
is illegal. | ||
|
||
Here are two possible ways to resolve this: | ||
|
||
1. Change the linearization order of Fail such that | ||
C comes before B. | ||
2. Alternatively, replace super.foo in the body of trait C by a | ||
super-call to a specific parent, e.g. super[A].foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class X | ||
class Y extends X | ||
|
||
trait A[+T] { | ||
def foo: T = null.asInstanceOf[T] | ||
} | ||
|
||
trait B extends A[X] { | ||
override def foo: X = new X | ||
} | ||
|
||
trait C extends A[Y] { | ||
override def foo: Y = new Y | ||
def superFoo: Y = super.foo // C will have an abstract `def C$$super$foo: Y` because of this call | ||
} | ||
|
||
class Fail extends B with C // error | ||
// Generated `def C$$super$foo: Y = super[B].foo` | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val y: Y = (new Fail).superFoo // Used to fail with a ClassCastException because of `Fail#C$$super$foo` being incorrect above | ||
assert(y == null) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.