@@ -8,6 +8,7 @@ import Constants.Constant
8
8
import DenotTransformers ._ , TreeTransforms ._ , Phases .Phase
9
9
import TypeErasure .ErasedValueType , ValueClasses ._
10
10
import dotty .tools .dotc .core .SymDenotations .ClassDenotation
11
+ import ElimErasedValueType .elimEVT
11
12
12
13
/** This phase erases arrays of value classes to their runtime representation.
13
14
*
@@ -30,7 +31,7 @@ class VCArrays extends MiniPhaseTransform with InfoTransformer {
30
31
tp match {
31
32
case JavaArrayType (ErasedValueType (tr, eund)) =>
32
33
val cls = tr.symbol.asClass
33
- defn.vcArrayOf (cls).typeRef
34
+ defn.vcDeepArrayOf (cls).typeRef
34
35
// case tp: MethodType =>
35
36
// val paramTypes = tp.paramTypes.mapConserve(eraseVCArrays)
36
37
// val retType = eraseVCArrays(tp.resultType)
@@ -59,8 +60,9 @@ class VCArrays extends MiniPhaseTransform with InfoTransformer {
59
60
// box body implementation
60
61
case _ if tree.name == nme.box && ValueClasses .isDerivedValueClass(tree.symbol.owner.companionClass) && ! tree.symbol.is(Flags .Bridge ) =>
61
62
val List (List (param)) = tree.vparamss
62
- val newParam = ref(param.symbol).ensureConforms(ValueClasses .underlyingOfValueClass(vc.asClass))
63
- val newRhs = New (vc.typeRef, newParam :: Nil ).ensureConforms(tree.tpt.tpe)
63
+ val newParam = ref(param.symbol)
64
+ val newRhs : Tree = if (param.tpt.symbol.isPrimitiveValueClass) newParam
65
+ else New (vc.typeRef, newParam.ensureConforms(elimEVT(ValueClasses .deepUnderlyingOfValueClass(vc.asClass))) :: Nil )
64
66
newRhs
65
67
case _ => tree.rhs
66
68
}
@@ -84,13 +86,14 @@ class VCArrays extends MiniPhaseTransform with InfoTransformer {
84
86
tree.tpe match {
85
87
// [arg1, arg2, ...] => new VCXArray([V.evt2u$(arg1), V.evt2u$(arg2), ...])
86
88
case JavaArrayType (ErasedValueType (tr, tund)) =>
89
+ val tund2 = elimEVT(tund)
87
90
val cls = tr.symbol.asClass
88
91
val evt2uMethod = ref(evt2u(cls))
89
92
// [V.evt2u$(arg1), V.evt2u$(arg2), ...]
90
- val underlyingArray = JavaSeqLiteral (tree.elems.map(evt2uMethod.appliedTo(_)), TypeTree (tund ))
93
+ val underlyingArray = JavaSeqLiteral (tree.elems.map(evt2uMethod.appliedTo(_)), TypeTree (tund2 ))
91
94
val mod = cls.companionModule
92
95
// new VCXArray([V.evt2u$(arg1), V.evt2u$(arg2), ...], VCXCompanion)
93
- New (defn.vcArrayOf (cls).typeRef, List (underlyingArray, ref(mod)))
96
+ New (defn.vcDeepArrayOf (cls).typeRef, List (underlyingArray, ref(mod)))
94
97
case _ =>
95
98
tree match {
96
99
case SeqLiteral (elems, tptr) =>
@@ -130,10 +133,11 @@ class VCArrays extends MiniPhaseTransform with InfoTransformer {
130
133
case jat@ JavaArrayType (ErasedValueType (tr, underlying)) =>
131
134
val cls = tr.symbol.asClass
132
135
val mod = cls.companionModule
136
+ val und2 = elimEVT(underlying)
133
137
// TODO: und1 should be processed in case of EVT
134
- val und1 = eraseVCArrays(underlying )
138
+ val und1 = eraseVCArrays(und2 )
135
139
val arTpe = jat.derivedJavaArrayType(und1)
136
- New (defn.vcArrayOf (cls).typeRef,
140
+ New (defn.vcDeepArrayOf (cls).typeRef,
137
141
List (newArray(und1, arTpe, tree.pos, dims.asInstanceOf [JavaSeqLiteral ]).ensureConforms(arTpe),
138
142
ref(mod)))
139
143
case _ : Type =>
@@ -144,7 +148,7 @@ class VCArrays extends MiniPhaseTransform with InfoTransformer {
144
148
val mod = cls.companionModule
145
149
val retTpt2 = eraseVCArrays(ins.asInstanceOf [Type ])
146
150
val Literal (Constant (compTptType)) = compTpt
147
- val compTpt2 = eraseVCArrays((compTptType.asInstanceOf [Type ]))
151
+ val compTpt2 = eraseVCArrays((elimEVT( compTptType.asInstanceOf [Type ]) ))
148
152
newArray(compTpt2, retTpt2, tree.pos, dims.asInstanceOf [JavaSeqLiteral ])
149
153
case _ =>
150
154
transformTypeOfTree(tree)
0 commit comments