@@ -43,7 +43,8 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
43
43
val hasAnnotation = hasVarargsAnnotation(sym)
44
44
val hasRepeatedParam = hasRepeatedParams(sym)
45
45
if hasRepeatedParam then
46
- if isJavaVarargsOverride || hasAnnotation || parentHasAnnotation(sym) then
46
+ val parentHasAnnotation = parentHasVarargsAnnotation(sym)
47
+ if isJavaVarargsOverride || hasAnnotation || parentHasAnnotation then
47
48
// java varargs are more restrictive than scala's
48
49
// see https://github.com/scala/bug/issues/11714
49
50
val validJava = isValidJavaVarArgs(sym.info)
@@ -54,7 +55,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
54
55
|""" .stripMargin,
55
56
sym.sourcePos)
56
57
else
57
- addVarArgsForwarder(sym, isJavaVarargsOverride, hasAnnotation)
58
+ addVarArgsForwarder(sym, isJavaVarargsOverride, hasAnnotation, parentHasAnnotation )
58
59
else if hasAnnotation then
59
60
report.error(" A method without repeated parameters cannot be annotated with @varargs" , sym.sourcePos)
60
61
end
@@ -79,7 +80,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
79
80
80
81
private def hasVarargsAnnotation (sym : Symbol )(using Context ) = sym.hasAnnotation(defn.VarargsAnnot )
81
82
82
- private def parentHasAnnotation (sym : Symbol )(using Context ) = sym.allOverriddenSymbols.exists(hasVarargsAnnotation)
83
+ private def parentHasVarargsAnnotation (sym : Symbol )(using Context ) = sym.allOverriddenSymbols.exists(hasVarargsAnnotation)
83
84
84
85
private def isVarargsMethod (sym : Symbol )(using Context ) =
85
86
hasVarargsAnnotation(sym) ||
@@ -259,14 +260,16 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
259
260
*
260
261
* @param original the original method symbol
261
262
* @param isBridge true if we are generating a "bridge" (synthetic override forwarder)
263
+ * @param hasAnnotation true if the method is annotated with `@varargs`
264
+ * @param parentHasAnnotation true if the method overrides a method that is annotated with `@varargs`
262
265
*
263
266
* A forwarder is necessary because the following holds:
264
267
* - the varargs in `original` will change from `RepeatedParam[T]` to `Seq[T]` after this phase
265
268
* - _but_ the callers of the method expect its varargs to be changed to `Array[? <: T]`
266
269
* The solution is to add a method that converts its argument from `Array[? <: T]` to `Seq[T]` and
267
270
* forwards it to the original method.
268
271
*/
269
- private def addVarArgsForwarder (original : Symbol , isBridge : Boolean , hasAnnotation : Boolean )(using Context ): Unit =
272
+ private def addVarArgsForwarder (original : Symbol , isBridge : Boolean , hasAnnotation : Boolean , parentHasAnnotation : Boolean )(using Context ): Unit =
270
273
val owner = original.owner
271
274
if ! owner.isClass then
272
275
report.error(" inner methods cannot be annotated with @varargs" , original.sourcePos)
@@ -281,7 +284,10 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
281
284
// The java-compatible forwarder symbol
282
285
val forwarder =
283
286
original.copy(
284
- flags = if isBridge then flags | Artifact else flags,
287
+ flags =
288
+ if isBridge then flags | Artifact
289
+ else if hasAnnotation && ! parentHasAnnotation then flags &~ Override
290
+ else flags,
285
291
info = toJavaVarArgs(original.info)
286
292
).asTerm
287
293
0 commit comments