Skip to content

Commit b828c69

Browse files
Replace "bridge" by more correct "forwarder"
1 parent 06c0ef7 commit b828c69

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
2828

2929
override def phaseName: String = ElimRepeated.name
3030

31-
override def changesMembers: Boolean = true // the phase adds vararg bridges
31+
override def changesMembers: Boolean = true // the phase adds vararg forwarders
3232

3333
def transformInfo(tp: Type, sym: Symbol)(using Context): Type =
3434
elimRepeated(tp)
@@ -37,7 +37,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
3737
super.transform(ref) match
3838
case ref1: SymDenotation if (ref1 ne ref) && overridesJava(ref1.symbol) =>
3939
// 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.
4141
ref1.copySymDenotation(initFlags = ref1.flags &~ Override)
4242
case ref1 =>
4343
ref1
@@ -131,7 +131,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
131131
sym.sourcePos)
132132
tree
133133
else
134-
addVarArgsBridge(tree, isOverride)
134+
addVarArgsForwarder(tree, isOverride)
135135
else
136136
tree
137137
else
@@ -157,46 +157,46 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
157157
case pt: PolyType =>
158158
isValidJavaVarArgs(pt.resultType)
159159
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)
161161

162162

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
169169
* flags of `ddef` except `Private`.
170170
*
171-
* A bridge is necessary because the following hold:
171+
* A forwarder is necessary because the following hold:
172172
* - the varargs in `ddef` will change from `RepeatedParam[T]` to `Seq[T]` after this phase
173173
* - _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
175175
* forwards it to `ddef`.
176176
*/
177-
private def addVarArgsBridge(ddef: DefDef, javaOverride: Boolean)(using ctx: Context): Tree =
177+
private def addVarArgsForwarder(ddef: DefDef, isBridge: Boolean)(using ctx: Context): Tree =
178178
val original = ddef.symbol.asTerm
179179
// For simplicity we always set the varargs flag
180180
// although it's not strictly necessary for overrides
181181
// (but it is for non-overrides)
182182
val flags = ddef.symbol.flags | JavaVarargs
183183

184-
// The java-compatible bridge symbol
185-
val bridge = original.copy(
184+
// The java-compatible forwarder symbol
185+
val sym = original.copy(
186186
// 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,
188188
info = toJavaVarArgs(ddef.symbol.info)
189189
).asTerm
190190

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))
194194
} match
195195
case Some(conflict) =>
196196
ctx.error(s"@varargs produces a forwarder method that conflicts with ${conflict.showDcl}", original.sourcePos)
197197
ddef
198198
case None =>
199-
val bridgeDef = polyDefDef(bridge.enteredAfter(thisPhase), trefs => vrefss => {
199+
val bridgeDef = polyDefDef(sym.enteredAfter(thisPhase), trefs => vrefss => {
200200
val init :+ (last :+ vararg) = vrefss
201201
// Can't call `.argTypes` here because the underlying array type is of the
202202
// form `Array[? <: SomeType]`, so we need `.argInfos` to get the `TypeBounds`.

0 commit comments

Comments
 (0)