Skip to content

Instantly share code, notes, and snippets.

@DarkDimius
Last active September 24, 2016 00:38
Show Gist options
  • Save DarkDimius/797c05a5fe38235a616478ff676db72a to your computer and use it in GitHub Desktop.
Save DarkDimius/797c05a5fe38235a616478ff676db72a to your computer and use it in GitHub Desktop.
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("...")
}
}
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