-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference fail with Array produces ClassCastException at runtime #5353
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5353?orig=1 |
@paulp said: object Test {
def main(args: Array[String]): Unit = List(Array(0), Array(0L)).map(x => x)
}
// java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object; |
@paulp said: |
@paulp said: |
@paulp said: |
@retronym said: scala> Array()
<console>:8: error: macro has not been expanded
Array()
^
scala> :type if (false) Array("qwe") else Array()
<console>:8: error: macro has not been expanded
if (false) Array("qwe") else Array()
^
<console>:8: error: macro has not been expanded
if (false) Array("qwe") else Array() The error message isn't stellar, but it beats a runtime error. |
@retronym said (edited on Jun 19, 2012 9:30:02 PM UTC): scala> List(Array(0), Array(0L)).map(x => x)bad option: '-nc'
res0: List[Array[_ >: Long with Int <: AnyVal]] = List(Array(0), Array(0)) With 2.10.0-M3 I saw: ~/code/scala ~/usr/scala-2.10.0-M3/bin/scala -nocompdaemon
Welcome to Scala version 2.10.0-M3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> List(Array(0), Array(0L)).map(x => x)
java.lang.AbstractMethodError
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:241)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:241)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:77)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:241) |
@paulp said:
|
@paulp said: scala> 5.getClass
res0: Class[Int] = int
scala> (5: AnyVal).getClass
java.lang.ClassCastException: java.lang.Integer cannot be cast to scala.AnyVal
scala> (5: Any).getClass
res1: Class[_] = class java.lang.Integer |
@odersky said: The getClass failure should be a separate ticket. Paul, I assume you have that on the radar already? |
@adriaanm said (edited on Jan 22, 2013 11:35:22 PM UTC): |
@xeno-by said: scala> lub(List(typeOf[Array[String]], typeOf[Array[Nothing]]))
res2: reflect.runtime.universe.Type = Array[_ <: String] I wonder how to reconcile this behavior of |
@paulp said (edited by @xeno-by on Apr 28, 2013 3:54:49 PM UTC):
|
@paulp said: |
@paulp said: |
@xeno-by said: |
@paulp said (edited by @xeno-by on Apr 28, 2013 8:44:14 PM UTC): |
@xeno-by said (edited on Apr 28, 2013 8:52:00 PM UTC): Welcome to Scala version 2.10.2-20130425-053916-403ba8938f (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> if (false) Array("qwe") else Array()
<console>:8: error: this type parameter must be specified
if (false) Array("qwe") else Array()
^
scala> if (false) Array("qwe") else Array[Nothing]()
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String; |
@adriaanm said: |
@paulp said: |
@retronym said: |
@paulp said: |
Expected: either compilation error, or correct inference for the second array creation
The text was updated successfully, but these errors were encountered: