Skip to content

Instantly share code, notes, and snippets.

@steshaw
Created June 2, 2023 08:33
Show Gist options
  • Save steshaw/57ebbd9929ea0a615d4d23c09cec8c05 to your computer and use it in GitHub Desktop.
Save steshaw/57ebbd9929ea0a615d4d23c09cec8c05 to your computer and use it in GitHub Desktop.
// https://github.com/namin/unsound/blob/master/unsound.scala
object unsound {
trait LowerBound[T] {
type M >: T;
}
trait UpperBound[U] {
type M <: U;
}
def coerce[T,U](t : T) : U = {
def upcast(ub : LowerBound[T], t : T) : ub.M = t
val bounded : LowerBound[T] with UpperBound[U] = null
return upcast(bounded, t)
}
def main(args : Array[String]) : Unit = {
val zero : String = coerce[Integer,String](0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment