Last active
December 18, 2015 18:09
-
-
Save Blaisorblade/5823556 to your computer and use it in GitHub Desktop.
Test clashes with mixins
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
/** | |
* Here we create a diamond inheritance structure with trait Client at the | |
* bottom. Trait Client inherits the same member from two traits. What does | |
* Scalac do here? | |
* | |
* Answers: | |
* | |
* - If the two members are abstract and have the same signature, they are | |
* merged and the code is accepted (see helper). | |
* - If they have the same signature and both have bodies, the code is | |
* rejected (see helper2). | |
* - If they have different signatures which could coexist as overloads, the | |
* code is still not accepted (they don't like Java-like overloading, after | |
* all) (see helper3). | |
*/ | |
trait Base { | |
def sum: Int = ??? //sum "+" sum | |
} | |
trait Variables extends Base { | |
override def sum = helper | |
def helper : Int | |
//def helper2 = letter | |
//def helper3 : Int => Int | |
def letter = ??? | |
} | |
trait Literals extends Base { | |
override def sum = helper | |
def helper : Int | |
//def helper2 = digit | |
//def helper3: String => String | |
def digit = ??? | |
} | |
trait Client extends Literals with Variables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment