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
Instantiating a generic value class results in a class cast exception when given a primitive array #7521
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7521?orig=1 |
@retronym said: scala> class C { new Wrapper(new Array[Int](0)) }
defined class C
scala> :javap -v C
...
{
public C();
Code:
Stack=2, Locals=1, Args_size=1
0: aload_0
1: invokespecial #9; //Method java/lang/Object."<init>":()V
4: getstatic #15; //Field scala/runtime/ScalaRunTime$.MODULE$:Lscala/runtime/ScalaRunTime$;
7: iconst_0
8: newarray int
10: invokevirtual #19; //Method scala/runtime/ScalaRunTime$.toObjectArray:(Ljava/lang/Object;)[Ljava/lang/Object;
13: checkcast #21; //class "[Ljava/lang/Integer;"
16: pop
17: return
LocalVariableTable:
Start Length Slot Name Signature
0 18 0 this LC;
LineNumberTable:
line 8: 0
} |
@retronym said: scala/scala@39fc4aa84#L1R740 erasedValueClassArg(<<Wrapper[Array[Int]]>>) = Array[Integer] |
@gkossakowski said: |
@retronym said: |
@retronym said: |
Scala 2.11 requires a special implementation of DataValue to work around scala/bug#7521
Scala 2.11 requires a special implementation of DataValue to work around scala/bug#7521
Scala 2.11 requires a special implementation of DataValue to work around scala/bug#7521
For performance reasons, we have been making extensive use of AnyRef to store data values in our infoset, and throughout the runtime. This allows us to avoid boxing, but prevents the type system from validating that unexepected types to not infect our values. This commit introduces a value type, DataValue, which provides a 0 overhead (eg. no boxing) wrapper around AnyRef, while only allowing a limited number of types to populate it. In doing so, an unrelated bug of mixing Java and Scala BigInts was uncovered and corrected. Such a bug should be much less likely to occur in the future. Due to a bug in Scala 2.11 (scala/bug#7521), we have 2 implementations of DataValue. The 2.11 version automatically boxes/unboxes all instances of Array[Byte] DAFFODIL-2169
For performance reasons, we have been making extensive use of AnyRef to store data values in our infoset, and throughout the runtime. This allows us to avoid boxing, but prevents the type system from validating that unexepected types to not infect our values. This commit introduces a value type, DataValue, which provides a 0 overhead (eg. no boxing) wrapper around AnyRef, while only allowing a limited number of types to populate it. In doing so, an unrelated bug of mixing Java and Scala BigInts was uncovered and corrected. Such a bug should be much less likely to occur in the future. Due to a bug in Scala 2.11 (scala/bug#7521), we have 2 implementations of DataValue. The 2.11 version automatically boxes/unboxes all instances of Array[Byte] DAFFODIL-2169
Similarly:
Note the primitive array being cast in the second example.
The text was updated successfully, but these errors were encountered: