-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Move mixin forwarders generation after erasure #6079
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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,5 @@ | ||
<527..527> in mixin-forwarder-clash1.scala | ||
Name clash between inherited members: | ||
override def concat(suffix: Int): X in trait OneB at line 10 and | ||
override def concat: [Dummy](suffix: Int): Y in trait TwoB at line 18 | ||
have the same type after erasure. |
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,38 @@ | ||
class Foo | ||
|
||
// Using self-types to force mixin forwarders | ||
|
||
trait OneA[X] { | ||
def concat(suffix: Int): X = ??? | ||
} | ||
|
||
trait OneB[X] { self: OneA[X] => | ||
override def concat(suffix: Int): X = ??? | ||
} | ||
|
||
trait TwoA[Y/* <: Foo*/] { | ||
def concat[Dummy](suffix: Int): Y = ??? | ||
} | ||
|
||
trait TwoB[Y/* <: Foo*/] { self: TwoA[Y] => | ||
override def concat[Dummy](suffix: Int): Y = ??? | ||
} | ||
|
||
class Bar1 extends OneA[Foo] with OneB[Foo] | ||
// Because mixin forwarders are generated after erasure, we get: | ||
// override def concat(suffix: Int): Object | ||
|
||
class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error | ||
// We get a mixin forwarder for TwoB: | ||
// override def concat(suffix: Int): Object | ||
// This clashes with the forwarder generated in Bar1, and the compiler detects that: | ||
// | ||
// |class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] | ||
// | ^ | ||
// | Name clash between inherited members: | ||
// | override def concat(suffix: Int): Object in trait OneB at line 10 and | ||
// | override def concat: [Dummy](suffix: Int): Y in trait TwoB at line 18 | ||
// | have the same type after erasure. | ||
// | ||
// This also works with separate compilation as demonstrated by | ||
// mixin-forwarder-clash2. |
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,5 @@ | ||
<6..6> in B_2.scala | ||
Name clash between inherited members: | ||
override def concat(suffix: Int): X in trait OneB and | ||
override def concat: [Dummy](suffix: Int): Y in trait TwoB | ||
have the same type after erasure. |
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,23 @@ | ||
class Foo | ||
|
||
// Using self-types to force mixin forwarders | ||
|
||
trait OneA[X] { | ||
def concat(suffix: Int): X = ??? | ||
} | ||
|
||
trait OneB[X] { self: OneA[X] => | ||
override def concat(suffix: Int): X = ??? | ||
} | ||
|
||
trait TwoA[Y/* <: Foo*/] { | ||
def concat[Dummy](suffix: Int): Y = ??? | ||
} | ||
|
||
trait TwoB[Y/* <: Foo*/] { self: TwoA[Y] => | ||
override def concat[Dummy](suffix: Int): Y = ??? | ||
} | ||
|
||
class Bar1 extends OneA[Foo] with OneB[Foo] | ||
// Because mixin forwarders are generated after erasure, we get: | ||
// override def concat(suffix: Int): Object |
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,16 @@ | ||
class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error | ||
// We get a mixin forwarder for TwoB: | ||
// override def concat(suffix: Int): Object | ||
// This clashes with the forwarder generated in Bar1, and | ||
// we can detect that even with separate compilation, | ||
// because forwarders are always generated after erasure | ||
// so their signature matches the erased signature of the | ||
// method they forward to, which double-defs check will | ||
// consider: | ||
// | ||
// |class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] | ||
// | ^ | ||
// | Name clash between inherited members: | ||
// | override def concat(suffix: Int): X in trait OneB and | ||
// | override def concat: [Dummy](suffix: Int): Y in trait TwoB | ||
// | have the same type after erasure. |
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,45 @@ | ||
// This test case used to fail when mixin forwarders were generated before erasure, | ||
// it doesn't anymore since the forwarders generated after erasure do not clash, | ||
// the comments are preserved for posterity. | ||
|
||
class Foo | ||
|
||
// Using self-types to force mixin forwarders | ||
|
||
trait OneA[X] { | ||
def concat(suffix: Int): X = ??? | ||
} | ||
|
||
trait OneB[X] { self: OneA[X] => | ||
override def concat(suffix: Int): X = ??? | ||
} | ||
|
||
trait TwoA[Y <: Foo] { | ||
def concat[Dummy](suffix: Int): Y = ??? | ||
} | ||
|
||
trait TwoB[Y <: Foo] { self: TwoA[Y] => | ||
override def concat[Dummy](suffix: Int): Y = ??? | ||
} | ||
|
||
class Bar1 extends OneA[Foo] with OneB[Foo] | ||
// Because mixin forwarders are generated before erasure, we get: | ||
// override def concat(suffix: Int): Foo | ||
|
||
class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error | ||
// We get a mixin forwarder for TwoB: | ||
// override def concat[Dummy](suffix: Int): Foo | ||
// which gets erased to: | ||
// override def concat(suffix: Int): Foo | ||
// This clashes with the forwarder generated in Bar1, and the compiler detects that: | ||
// | ||
// |class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] | ||
// | ^ | ||
// | Name clash between defined and inherited member: | ||
// | override def concat(suffix: Int): Foo in class Bar1 and | ||
// | override def concat: [Dummy](suffix: Int): Foo in class Bar2 | ||
// | have the same type after erasure. | ||
// | ||
// But note that the compiler is able to see the mixin forwarder in Bar1 | ||
// only because of joint compilation, this doesn't work with separate | ||
// compilation as in mixin-forwarder-clash2. |
Oops, something went wrong.
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.