@@ -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) ||
@@ -266,7 +267,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
266
267
* The solution is to add a method that converts its argument from `Array[? <: T]` to `Seq[T]` and
267
268
* forwards it to the original method.
268
269
*/
269
- private def addVarArgsForwarder (original : Symbol , isBridge : Boolean , hasAnnotation : Boolean )(using Context ): Unit =
270
+ private def addVarArgsForwarder (original : Symbol , isBridge : Boolean , hasAnnotation : Boolean , parentHasAnnotation : Boolean )(using Context ): Unit =
270
271
val owner = original.owner
271
272
if ! owner.isClass then
272
273
report.error(" inner methods cannot be annotated with @varargs" , original.sourcePos)
@@ -281,7 +282,10 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
281
282
// The java-compatible forwarder symbol
282
283
val forwarder =
283
284
original.copy(
284
- flags = if isBridge then flags | Artifact else flags,
285
+ flags =
286
+ if isBridge then flags | Artifact
287
+ else if hasAnnotation && ! parentHasAnnotation then flags &~ Override
288
+ else flags,
285
289
info = toJavaVarArgs(original.info)
286
290
).asTerm
287
291
0 commit comments