Skip to content

Commit 8bfc293

Browse files
committed
Make Array.apply an intrinsic
1 parent 1be790c commit 8bfc293

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ object Objects:
616616
* @param superType The type of the super in a super call. NoType for non-super calls.
617617
* @param needResolve Whether the target of the call needs resolution?
618618
*/
619-
def call(value: Value, meth: Symbol, args: List[ArgInfo], receiver: Type, superType: Type, needResolve: Boolean = true): Contextual[Value] = log("call " + meth.show + ", args = " + args.map(_.value.show), printer, (_: Value).show) {
619+
def call(value: Value, meth: Symbol, args: List[ArgInfo], receiver: Type, superType: Type, needResolve: Boolean = true): Contextual[Value] = log("call " + meth.show + ", this = " + value.show + ", args = " + args.map(_.value.show), printer, (_: Value).show) {
620620
value match
621621
case Cold =>
622622
report.warning("Using cold alias. Calling trace:\n" + Trace.show, Trace.position)
@@ -658,7 +658,11 @@ object Objects:
658658
resolve(ref.klass, meth)
659659

660660
if target.isOneOf(Flags.Method) then
661-
if target.hasSource then
661+
if target.owner == defn.ArrayModuleClass && target.name == nme.apply then
662+
val arr = OfArray(State.currentObject, summon[Regions.Data])
663+
Heap.write(arr.addr, args.map(_.value).join)
664+
arr
665+
else if target.hasSource then
662666
val cls = target.owner.enclosingClass.asClass
663667
val ddef = target.defTree.asInstanceOf[DefDef]
664668
val meth = ddef.symbol
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object A:
2+
class Box(var value: Int)
3+
val box: Box = new Box(0)
4+
5+
object B:
6+
val boxes: Array[A.Box] = Array(A.box)
7+
val box: A.Box = boxes(0)
8+
val x: Int = box.value // error

0 commit comments

Comments
 (0)