Open tyukiand opened 6 years ago
Just for fun, eliminating the asInstanceOf
:
import scala.language.higherKinds
class Foo[X]
class Bar[X]
class CrashIt[A[_] >: Null] {
def cast(a: Any): A[Int] = null
}
val c = if (true) new CrashIt[Foo] else new CrashIt[Bar]
val x = c.cast("")
Even shorter: without >: Null
and without returning any instances at all:
import scala.language.higherKinds
class Foo[X]
class Bar[X]
class CrashIt[A[_]] {
def cast(a: Any): A[Int] = ???
}
val c = if (true) new CrashIt[Foo] else new CrashIt[Bar]
val x = c.cast("")
(That's not purely code-golfing, this has fewer syntactic elements, and it has the advantage of a somewhat shorter stack trace of the error.)
Ugh, just this line kills the REPL:
class CrashIt[A[_]]
if (true) new CrashIt[Option] else new CrashIt[List]
Ugh, just this line kills the REPL
Yes, but it "works" outside of the REPL though... This is a very dangerous corner of the compiler :-p
This goes way farther back (before 2.11, even).
Uh-oh, note the ill-kinded type inference:
scala> List(new CrashIt[Option], new CrashIt[List])
<console>:39: error: type mismatch;
found : CrashIt[Option]
required: CrashIt[_ >: List with Option <: Product with Serializable]
List(new CrashIt[Option], new CrashIt[List])
^
<console>:39: error: type mismatch;
found : CrashIt[List]
required: CrashIt[_ >: List with Option <: Product with Serializable]
List(new CrashIt[Option], new CrashIt[List])
^
Also, I don't understand why:
can't existentially abstract over parameterized type
https://github.com/scala/scala/pull/6352 promotes this to an error for 2.13
My PR is just not to crash when constructing a string.
scala 2.12.4 typechecker crashes when trying to run the following script with "scala script.scala":
Stack trace:
Information about the used compiler and environment:
Some observations:
c.cast("")
is removed