dotty
dotty copied to clipboard
Can't call generic method with array of value type
If we have Java code
class Foo {
public static<T> void foo(T[] arr) {}
}
we can no longer call it from Scala with an argument that's an array of a value type
class Bar { // in Scala
val arr: Array[Int] = ???
Foo.foo(arr) // error: expected Array[Int|JavaNull]|JavaNull, but got Array[Int]
}
Instead, we need to make arr nullable: val arr: Array[Int|Null] = ???, which is bad for performance. Pre explicit nulls, this used to work because the array was automatically copied to an Array[Object] at the callsite.
See https://github.com/abeln/dotty/commit/59671f7e86ee68dddf21016b3e0b5acdc0371e90#diff-459714fae8d4a9d0faf4dee5e40a5b2dR1 for the test that motivated this.
@olhotak do you remember what we agreed for this one?