@@ -28,7 +28,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
28
28
29
29
override def phaseName : String = ElimRepeated .name
30
30
31
- override def changesMembers : Boolean = true // the phase adds vararg bridges
31
+ override def changesMembers : Boolean = true // the phase adds vararg forwarders
32
32
33
33
def transformInfo (tp : Type , sym : Symbol )(using Context ): Type =
34
34
elimRepeated(tp)
@@ -37,7 +37,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
37
37
super .transform(ref) match
38
38
case ref1 : SymDenotation if (ref1 ne ref) && overridesJava(ref1.symbol) =>
39
39
// This method won't override the corresponding Java method at the end of this phase,
40
- // only the bridge added by `addVarArgsBridge ` will.
40
+ // only the forwarder added by `addVarArgsForwarder ` will.
41
41
ref1.copySymDenotation(initFlags = ref1.flags &~ Override )
42
42
case ref1 =>
43
43
ref1
@@ -131,7 +131,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
131
131
sym.sourcePos)
132
132
tree
133
133
else
134
- addVarArgsBridge (tree, isOverride)
134
+ addVarArgsForwarder (tree, isOverride)
135
135
else
136
136
tree
137
137
else
@@ -157,46 +157,46 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
157
157
case pt : PolyType =>
158
158
isValidJavaVarArgs(pt.resultType)
159
159
case _ =>
160
- throw new Exception (" Match error in @varargs bridge logic . This should not happen, please open an issue " + tp)
160
+ throw new Exception (" Match error in @varargs checks . This should not happen, please open an issue " + tp)
161
161
162
162
163
- /** Add a Java varargs bridge
164
- * @param ddef the original method definition
165
- * @param addFlag the flag to add to the method symbol
166
-
167
- * @return a thicket consisting of `ddef` and a varargs bridge method
168
- * which forwards java varargs to `ddef`. It retains all the
163
+ /** Add a Java varargs forwarder
164
+ * @param ddef the original method definition
165
+ * @param isBridge true if we are generating a "bridge" (synthetic override forwarder)
166
+ *
167
+ * @return a thicket consisting of `ddef` and an additional method
168
+ * that forwards java varargs to `ddef`. It retains all the
169
169
* flags of `ddef` except `Private`.
170
170
*
171
- * A bridge is necessary because the following hold:
171
+ * A forwarder is necessary because the following hold:
172
172
* - the varargs in `ddef` will change from `RepeatedParam[T]` to `Seq[T]` after this phase
173
173
* - _but_ the callers of `ddef` expect its varargs to be changed to `Array[? <: T]`
174
- * The solution is to add a "bridge" method that converts its argument from `Array[? <: T]` to `Seq[T]` and
174
+ * The solution is to add a method that converts its argument from `Array[? <: T]` to `Seq[T]` and
175
175
* forwards it to `ddef`.
176
176
*/
177
- private def addVarArgsBridge (ddef : DefDef , javaOverride : Boolean )(using ctx : Context ): Tree =
177
+ private def addVarArgsForwarder (ddef : DefDef , isBridge : Boolean )(using ctx : Context ): Tree =
178
178
val original = ddef.symbol.asTerm
179
179
// For simplicity we always set the varargs flag
180
180
// although it's not strictly necessary for overrides
181
181
// (but it is for non-overrides)
182
182
val flags = ddef.symbol.flags | JavaVarargs
183
183
184
- // The java-compatible bridge symbol
185
- val bridge = original.copy(
184
+ // The java-compatible forwarder symbol
185
+ val sym = original.copy(
186
186
// non-overrides cannot be synthetic otherwise javac refuses to call them
187
- flags = if javaOverride then flags | Artifact else flags,
187
+ flags = if isBridge then flags | Artifact else flags,
188
188
info = toJavaVarArgs(ddef.symbol.info)
189
189
).asTerm
190
190
191
- currentClass.info.member(bridge .name).alternatives.find { s =>
192
- s.matches(bridge ) &&
193
- ! (javaOverride && s.asSymDenotation.is(JavaDefined ))
191
+ currentClass.info.member(sym .name).alternatives.find { s =>
192
+ s.matches(sym ) &&
193
+ ! (isBridge && s.asSymDenotation.is(JavaDefined ))
194
194
} match
195
195
case Some (conflict) =>
196
196
ctx.error(s " @varargs produces a forwarder method that conflicts with ${conflict.showDcl}" , original.sourcePos)
197
197
ddef
198
198
case None =>
199
- val bridgeDef = polyDefDef(bridge .enteredAfter(thisPhase), trefs => vrefss => {
199
+ val bridgeDef = polyDefDef(sym .enteredAfter(thisPhase), trefs => vrefss => {
200
200
val init :+ (last :+ vararg) = vrefss
201
201
// Can't call `.argTypes` here because the underlying array type is of the
202
202
// form `Array[? <: SomeType]`, so we need `.argInfos` to get the `TypeBounds`.
0 commit comments