Unsoundness due to type projections (no null or lazy vals necessary) (not in strict mode)
See original GitHub issueEDIT: simpler example in the comments below
object App {
abstract class Boo[E <: Nothing { type R }] {
val r: E
type R = r.type#R
}
trait Leibniz[+U, A <: U, B <: U] {
def subst[F[_ <: U]](fa : F[A]): F[B]
}
def refl[A]: Leibniz[A, A, A] = new Leibniz[A, A, A] {
def subst[F[_ <: A]](fa : F[A]): F[A] = fa
}
val p = refl[Nothing] : Leibniz[Nothing {type R}, Nothing { type R = Int }, Nothing { type R = String }]
def main(args : Array[String]): Unit = {
// BOOM
val s : String = p.subst[[x <: Nothing { type R }] => Boo[x]#R](10)
}
}
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at App$.main(App.scala:18)
at App.main(App.scala)
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
isVolatile incorrect for intersection types #50 - lampepfl/dotty
This code is type correct for any T, a and b are always initialized to null , there is no particular place to...
Read more >Explicit Nulls - Scala 3
Explicit nulls is an opt-in feature that modifies the Scala type system, which makes reference types (anything that extends AnyRef ) non-nullable.
Read more >`def` vs `val` vs `lazy val` evaluation in Scala - Stack Overflow
lazy val defines a value with delayed initialization. It will be initialized when it's first used, so the assignment expression will be evaluated...
Read more >Guide to lazy val in Scala - Baeldung
Learn how Scala implements its lazy val feature and some problems you may encounter when using it.
Read more >Advanced Logical Type Systems for Untyped Languages
expressive but unchecked (and thus unsound) type predicates. ... occurrence typing is necessary but not sufficient for type checking many ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Refinements of
Nothing
are bad, but I can do it entirely without refiningNothing
😸Adapted https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/ to this technique: