Last active
September 24, 2016 00:38
-
-
Save DarkDimius/797c05a5fe38235a616478ff676db72a to your computer and use it in GitHub Desktop.
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
object unsoundForwardRef { | |
trait LowerBound[T] { | |
type M >: T; | |
} | |
trait UpperBound[U] { | |
type M <: U; | |
} | |
val bounded1 : LowerBound[Int] with UpperBound[String] = hideForwardRef | |
val bounded2 : LowerBound[Int] with UpperBound[String] = bounded1 | |
def hideForwardRef = bounded2 | |
def upcast[T](ub : LowerBound[T], t : T) : ub.M = t | |
def main(args : Array[String]) : Unit = { | |
val zero : String = upcast(bounded1, 0) | |
println("...") | |
} | |
} |
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
object unsoundStatics { | |
trait LowerBound[T] { | |
type M >: T; | |
} | |
trait UpperBound[U] { | |
type M <: U; | |
} | |
object Coerce1 { | |
val bounded : LowerBound[Int] with UpperBound[String] = Coerce1.bounded | |
} | |
object Coerce2 { | |
val bounded : LowerBound[Int] with UpperBound[String] = Coerce2.bounded | |
} | |
def upcast[T](ub : LowerBound[T], t : T) : ub.M = t | |
def main(args : Array[String]) : Unit = { | |
val zero : String = upcast(Coerce1.bounded, 0) | |
println("...") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment