Skip to content

Instantly share code, notes, and snippets.

@Blaisorblade
Last active December 18, 2015 18:09
Show Gist options
  • Save Blaisorblade/5823556 to your computer and use it in GitHub Desktop.
Save Blaisorblade/5823556 to your computer and use it in GitHub Desktop.
Test clashes with mixins
/**
* 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