@@ -39,11 +39,11 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
3939 * The definitions (DefDef) for these symbols are created by transformDefDef.
4040 */
4141 override def transform (ref : SingleDenotation )(using Context ): SingleDenotation =
42- def transformVarArgs (sym : Symbol , isJavaOverride : Boolean ): Unit =
42+ def transformVarArgs (sym : Symbol , isJavaVarargsOverride : Boolean ): Unit =
4343 val hasAnnotation = hasVarargsAnnotation(sym)
4444 val hasRepeatedParam = hasRepeatedParams(sym)
4545 if hasRepeatedParam then
46- if isJavaOverride || hasAnnotation || parentHasAnnotation(sym) then
46+ if isJavaVarargsOverride || hasAnnotation || parentHasAnnotation(sym) then
4747 // java varargs are more restrictive than scala's
4848 // see https://github.com/scala/bug/issues/11714
4949 val validJava = isValidJavaVarArgs(sym.info)
@@ -54,17 +54,17 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
5454 |""" .stripMargin,
5555 sym.sourcePos)
5656 else
57- addVarArgsForwarder(sym, isJavaOverride , hasAnnotation)
57+ addVarArgsForwarder(sym, isJavaVarargsOverride , hasAnnotation)
5858 else if hasAnnotation
5959 report.error(" A method without repeated parameters cannot be annotated with @varargs" , sym.sourcePos)
6060 end
6161
6262 super .transform(ref) match
63- case ref1 : SymDenotation if ref1.is(Method ) =>
63+ case ref1 : SymDenotation if ref1.is(Method , butNot = JavaDefined ) =>
6464 val sym = ref1.symbol
65- val isJavaOverride = (ref1 ne ref) && overridesJava(sym) // (ref1 ne ref) avoids cycles
66- transformVarArgs(sym, isJavaOverride )
67- if isJavaOverride then
65+ val isJavaVarargsOverride = (ref1 ne ref) && overridesJava(sym)
66+ transformVarArgs(sym, isJavaVarargsOverride )
67+ if isJavaVarargsOverride then
6868 // This method won't override the corresponding Java method at the end of this phase,
6969 // only the forwarder added by `addVarArgsForwarder` will.
7070 ref1.copySymDenotation(initFlags = ref1.flags &~ Override )
@@ -267,7 +267,6 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
267267 return
268268
269269 val classInfo = owner.info
270- val decls = classInfo.decls.cloneScope
271270
272271 // For simplicity we always set the varargs flag,
273272 // although it's not strictly necessary for overrides.
@@ -280,22 +279,21 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
280279 info = toJavaVarArgs(original.info)
281280 ).asTerm
282281
283- // Find a method that would conflict with the forwarder if the latter existed.
282+ // Find methods that would conflict with the forwarder if the latter existed.
284283 // This needs to be done at thisPhase so that parent @varargs don't conflict.
285- val conflict =
286- classInfo.member(original.name).alternatives.find { s =>
287- s.matches(forwarder) &&
288- ! (isBridge && s.asSymDenotation.is(JavaDefined ))
284+ val conflicts =
285+ classInfo.member(original.name).altsWith { s =>
286+ s.matches(forwarder) && ! (isBridge && s.is(JavaDefined ))
289287 }
290- conflict match
291- case Some ( conflict) =>
288+ conflicts match
289+ case conflict :: _ =>
292290 val src =
293291 if hasAnnotation then " @varargs"
294292 else if isBridge then " overriding a java varargs method"
295293 else " @varargs (on overriden method)"
296294 report.error(s " $src produces a forwarder method that conflicts with ${conflict.showDcl}" , original.sourcePos)
297- case None =>
298- decls.enter( forwarder.enteredAfter(thisPhase) )
295+ case Nil =>
296+ forwarder.enteredAfter(thisPhase)
299297
300298 /** Convert type from Scala to Java varargs method */
301299 private def toJavaVarArgs (tp : Type )(using Context ): Type = tp match
0 commit comments