scala/scala — pull request #1568 by retronym (2012-11-03 22:41:22+00:00)
Title: SI-6611 Tighten up an unsafe array optimization

The net was cast too wide and was unsafely optimizing away array
copies.

review by @paulp

I'd like to move the following to `Definitions`, but I'm not what I can use in there to pick a particular overload when arity isn't enough.

```scala
ArrayModule_overloadedApply.suchThat {
_.tpe.resultType.dealias.typeSymbol == ObjectClass // [T: ClassTag](xs: T*): Array[T] post erasure
})
```

One idea I had was to annotate such methods:

```scala
object Array {
@scala.annotation.internal.magic("Array_apply_ref")
def apply[T: ClassTag](args: T*)
```

It would simplify the compiler logic and make it more self evident in the source that this method is treated specially by the compiler. But maybe they should just be macros, which would be even more revealing.

Relates to SI-6247, in that it shows where one overload of `Array.apply` is already optimized, and where the corresponding primitive optimizations could go (again, unless macros are preferred.)