Created
June 2, 2023 08:33
-
-
Save steshaw/57ebbd9929ea0a615d4d23c09cec8c05 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
// 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