-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow mixins where super calls bind to vals (#16908)
Forward port of scala/scala#10268 Fixes #16704
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,17 @@ | ||
trait A { def f: String } | ||
trait B extends A { def f = "B" } | ||
trait C extends A { override val f = "C" } | ||
trait D extends C { override val f = "D" } | ||
trait E extends A, B { def d = super.f } | ||
final class O1 extends B, C, D, E // error: parent trait E has a super call which binds to the value D.f. Super calls can only target methods. | ||
final class O2 extends B, C, E, D // error: parent trait E has a super call which binds to the value C.f. Super calls can only target methods. | ||
final class O3 extends B, E, C, D | ||
|
||
object Main: | ||
def main(args: Array[String]): Unit = | ||
println(O1().f) // D | ||
println(O2().f) // D | ||
println(O3().f) // D | ||
println(O3().d) // B | ||
O1().d // was: NoSuchMethodError: 'java.lang.String D.f$(D)' | ||
O2().d // was: NoSuchMethodError: 'java.lang.String C.f$(C)' |
This file contains 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 @@ | ||
trait B: | ||
def f: Float = 1.0f | ||
|
||
class A(override val f: Float) extends B | ||
|
||
trait C extends B: | ||
abstract override val f = super.f + 100.0f | ||
|
||
trait D extends B: | ||
abstract override val f = super.f + 1000.0f | ||
|
||
class ACD10 extends A(10.0f) with C with D // error: parent trait D has a super call to method B.f, which binds to the value C.f. Super calls can only target methods. | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = | ||
new ACD10 // was: NoSuchMethodError: 'float C.f$(C)' |