File tree 1 file changed +10
-1
lines changed
compiler/src/dotty/tools/dotc/transform 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,13 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
125
125
* @return a thicket consisting of `ddef` and a varargs bridge method
126
126
* which overrides the Java varargs method JM from this phase on
127
127
* and forwards to `ddef`.
128
+ *
129
+ * A bridge is necessary because the following hold
130
+ * - the varargs in `ddef` will change from `RepeatedParam[T]` to `Seq[T]` after this phase
131
+ * - _but_ the callers of `ddef` expect its varargs to be changed to `Array[_ <: T]`, since it overrides
132
+ * a Java varargs
133
+ * The solution is to add a "bridge" method that converts its argument from `Array[_ <: T]` to `Seq[T]` and
134
+ * forwards it to `ddef`.
128
135
*/
129
136
private def addVarArgsBridge (ddef : DefDef )(implicit ctx : Context ): Tree = {
130
137
val original = ddef.symbol.asTerm
@@ -133,7 +140,9 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
133
140
info = toJavaVarArgs(ddef.symbol.info)).enteredAfter(thisPhase).asTerm
134
141
val bridgeDef = polyDefDef(bridge, trefs => vrefss => {
135
142
val (vrefs :+ varArgRef) :: vrefss1 = vrefss
136
- val elemtp = varArgRef.tpe.widen.argTypes.head
143
+ // Can't call `.argTypes` here because the underlying array type is of the
144
+ // form `Array[_ <: SomeType]`, so we need `.argInfos` to get the `TypeBounds`.
145
+ val elemtp = varArgRef.tpe.widen.argInfos.head
137
146
ref(original.termRef)
138
147
.appliedToTypes(trefs)
139
148
.appliedToArgs(vrefs :+ tpd.wrapArray(varArgRef, elemtp))
You can’t perform that action at this time.
0 commit comments