Last active
April 19, 2017 08:53
-
-
Save DarkDimius/6c5a341f324a63fa7077 to your computer and use it in GitHub Desktop.
Reachability examples
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
trait A {/* has a `def toString: String` inherited from scala.Any */} | |
class B extends A { override def toString = "B"} | |
class C extends A { override def toString = "C" /* is this dead code? */ } | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toString // does it call .toString on all the A’s? | |
val b: B = new B; | |
val c: C = new C; | |
foo(b) | |
} |
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
trait A {/* has a `def toString: String` inherited from scala.Any */} | |
class B extends A { override def toString = "B" /* is this dead code? */} | |
class C extends B { override def toString = "C"} | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toString // does it call .toString on all the A’s? | |
val b: B = new B; | |
val c: C = new C; | |
foo(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
trait A {/* has a `def toString: String` inherited from scala.Any */} | |
trait B extends A { override def toString = super.toString + "B" /* is this dead code? */} | |
trait C extends A { override def toString = super.toString + "C" /* is this dead code? */} | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toString // does it call .toString on all the A’s? | |
val b: B = new B with C{}; | |
foo(b) | |
} |
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
trait A {/* has a `def toString: String` inherited from scala.Any */} | |
trait B extends A { override def toString = super[A].toString + "B" /* is this dead code? */} // triggers https://issues.scala-lang.org/browse/SI-9645 | |
trait C extends A { override def toString = super.toString + "C" /* is this dead code? */} | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toString // does it call .toString on all the A’s? | |
val b: B = new B with C{}; | |
foo(b) | |
} |
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
trait A { type I; val s: I; def toString = s.toString} | |
class B extends A { type I = Int; val s = 0;} | |
class E { override def toString = ??? /* is this dead code? */} | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toString // does it call .toString on all the A’s? | |
val b: B = new B; | |
val e: E = new E; | |
foo(b) | |
} |
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
trait A {/* has a `def toString: String` inherited from scala.Any */} | |
class B {self => class Inner extends A {override def toString = self.toString}} | |
class C extends B{ override def toString = "B" /* is this dead code? */ } | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toString // does it call .toString on all the A’s? | |
val c: B = new C; | |
val inner = new (c.Inner) | |
foo(inner) | |
} |
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
trait A { def toStringUnapplied: () => String} | |
class B {self => class Inner extends A {def toStringUnapplied = self.toString _ }} | |
class C extends B { override def toString = "B" /* is this dead code? */ } | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toStringUnapplied | |
val c: B = new C; | |
val inner = new (c.Inner) | |
foo(inner) | |
} |
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
class A { def toString = "A"} | |
class B { def toString = "B"} | |
def main(a: Array[String]): Unit = { | |
def foo[A](a: A) = a.toString | |
val a: A = new A; | |
val b: B = new B; | |
foo(a) | |
} |
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
trait A | |
class B {self => class Inner extends A { override def toString = self.toString}} | |
class C[T](val f: T) extends B { override def toString = f.toString} | |
class E {override def toString = "E" /* is this dead code? */ } | |
def main(a: Array[String]): Unit = { | |
def foo(a: A) = a.toString // does it call .toString on all the A’s? | |
val e: E = new E | |
val c: B = new C(1); | |
val inner = new (c.Inner) | |
foo(inner) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why Go compiler quickly and Scala so slow?