@@ -128,15 +128,15 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
128
128
| - there must be a single repeated parameter
129
129
| - it must be the last argument in the last parameter list
130
130
|""" .stripMargin,
131
- tree .sourcePos)
131
+ sym .sourcePos)
132
132
tree
133
133
else
134
134
addVarArgsBridge(tree, isOverride)
135
135
else
136
136
tree
137
137
else
138
138
if hasAnnotation then
139
- ctx.error(" A method without repeated parameters cannot be annotated with @varargs" , tree .sourcePos)
139
+ ctx.error(" A method without repeated parameters cannot be annotated with @varargs" , sym .sourcePos)
140
140
tree
141
141
}
142
142
@@ -156,7 +156,8 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
156
156
lastp.last.isRepeatedParam
157
157
case pt : PolyType =>
158
158
isValidJavaVarArgs(pt.resultType)
159
- case _ => false
159
+ case _ =>
160
+ throw new Exception (" Match error in @varargs bridge logic. This should not happen, please open an issue " + tp)
160
161
161
162
162
163
/** Add a Java varargs bridge
@@ -179,22 +180,23 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
179
180
// although it's not strictly necessary for overrides
180
181
// (but it is for non-overrides)
181
182
val flags = ddef.symbol.flags | JavaVarargs
183
+
184
+ // The java-compatible bridge symbol
182
185
val bridge = original.copy(
183
186
// non-overrides cannot be synthetic otherwise javac refuses to call them
184
187
flags = if javaOverride then flags | Artifact else flags,
185
188
info = toJavaVarArgs(ddef.symbol.info)
186
- ).enteredAfter(thisPhase). asTerm
189
+ ).asTerm
187
190
188
- val bridgeDenot = bridge.denot
189
191
currentClass.info.member(bridge.name).alternatives.find { s =>
190
- s.matches(bridgeDenot ) &&
191
- ! (s.asSymDenotation.is(JavaDefined ) && javaOverride )
192
+ s.matches(bridge ) &&
193
+ ! (javaOverride && s.asSymDenotation.is(JavaDefined ))
192
194
} match
193
195
case Some (conflict) =>
194
- ctx.error(s " @varargs produces a forwarder method that conflicts with ${conflict.showDcl}" , ddef .sourcePos)
195
- EmptyTree
196
+ ctx.error(s " @varargs produces a forwarder method that conflicts with ${conflict.showDcl}" , original .sourcePos)
197
+ ddef
196
198
case None =>
197
- val bridgeDef = polyDefDef(bridge, trefs => vrefss => {
199
+ val bridgeDef = polyDefDef(bridge.enteredAfter(thisPhase) , trefs => vrefss => {
198
200
val init :+ (last :+ vararg) = vrefss
199
201
// Can't call `.argTypes` here because the underlying array type is of the
200
202
// form `Array[? <: SomeType]`, so we need `.argInfos` to get the `TypeBounds`.
@@ -213,16 +215,16 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
213
215
214
216
/** Convert type from Scala to Java varargs method */
215
217
private def toJavaVarArgs (tp : Type )(using Context ): Type = tp match
216
- case tp : PolyType =>
217
- tp.derivedLambdaType(tp.paramNames, tp.paramInfos, toJavaVarArgs(tp.resultType))
218
- case tp : MethodType =>
219
- tp.resultType match
220
- case m : MethodType => // multiple param lists
221
- tp.derivedLambdaType(tp.paramNames, tp.paramInfos, toJavaVarArgs(m))
222
- case _ =>
223
- val init :+ last = tp.paramInfos
224
- val vararg = varargArrayType(last)
225
- tp.derivedLambdaType(tp.paramNames, init :+ vararg, tp.resultType)
218
+ case tp : PolyType =>
219
+ tp.derivedLambdaType(tp.paramNames, tp.paramInfos, toJavaVarArgs(tp.resultType))
220
+ case tp : MethodType =>
221
+ tp.resultType match
222
+ case m : MethodType => // multiple param lists
223
+ tp.derivedLambdaType(tp.paramNames, tp.paramInfos, toJavaVarArgs(m))
224
+ case _ =>
225
+ val init :+ last = tp.paramInfos
226
+ val vararg = varargArrayType(last)
227
+ tp.derivedLambdaType(tp.paramNames, init :+ vararg, tp.resultType)
226
228
227
229
/** Translate a repeated type T* to an `Array[? <: Upper]`
228
230
* such that it is compatible with java varargs.
0 commit comments