-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Drop incorrect super accessor in trait subclass #17062
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
dwijnand
merged 4 commits into
scala:main
from
dwijnand:fix-trait-super-val-protected-accessors
Mar 23, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3cb01d6
Drop incorrect super accessor in trait subclass
dwijnand 121af88
Add a Java protected member case, which can only call super
dwijnand 0dea6c0
Fail the Java protected member case, rather than be wierd
dwijnand f8fb548
Skip Java using run test when scalajs
dwijnand 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Derives from run/i17021.defs, but with a Java protected member | ||
package p1; | ||
|
||
public class A { | ||
protected int foo() { return 1; } | ||
} |
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,14 @@ | ||
// Derives from run/i17021.defs | ||
// but with a Java protected member | ||
// which leads to a compile error | ||
package p2: | ||
trait B extends p1.A: | ||
def bar: Int = foo // error: method bar accesses protected method foo inside a concrete trait method: use super.foo instead | ||
|
||
class C extends B: | ||
override def foo: Int = 2 | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = | ||
val n = new p2.C().bar | ||
assert(n == 2, n) |
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,16 @@ | ||
// Derives from run/i17021, but with defs instead of vals | ||
package p1: | ||
class A: | ||
protected def foo: Int = 1 | ||
|
||
package p2: | ||
trait B extends p1.A: | ||
def bar: Int = foo | ||
|
||
class C extends B: | ||
override def foo: Int = 2 | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = | ||
val n = new p2.C().bar | ||
assert(n == 2, n) // was: assertion failed: 1 |
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,6 @@ | ||
// Derives from run/i17021.defs, but with a Java protected member | ||
package p1; | ||
|
||
public class A { | ||
protected int foo() { return 1; } | ||
} |
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,15 @@ | ||
// scalajs: --skip | ||
// Derives from run/i17021.defs | ||
// but with a Java protected member | ||
// and fixed calling code, that uses super | ||
package p2: | ||
trait B extends p1.A: | ||
def bar: Int = super.foo | ||
|
||
class C extends B: | ||
override def foo: Int = 2 | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = | ||
val n = new p2.C().bar | ||
assert(n == 1, n) |
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,18 @@ | ||
package p1: | ||
class A: | ||
protected val foo: Int = 1 | ||
|
||
package p2: | ||
trait B extends p1.A: | ||
def bar: Int = foo | ||
|
||
class C extends B: // was: error: parent trait B has a super call which binds to the value p1.A.foo. Super calls can only target methods. | ||
override val foo: Int = 2 | ||
|
||
// Also, assert that the access continues to delegate: | ||
// i.e. B#bar delegates to this.foo and so C#bar returns 2, | ||
// not B#bar delegates to super.foo and so C#bar returns 1. | ||
object Test: | ||
def main(args: Array[String]): Unit = | ||
val n = new p2.C().bar | ||
assert(n == 2, n) // was: assertion failed: 1 |
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.