@@ -39,11 +39,11 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
39
39
* The definitions (DefDef) for these symbols are created by transformDefDef.
40
40
*/
41
41
override def transform (ref : SingleDenotation )(using Context ): SingleDenotation =
42
- def transformVarArgs (sym : Symbol , isJavaOverride : Boolean ): Unit =
42
+ def transformVarArgs (sym : Symbol , isJavaVarargsOverride : Boolean ): Unit =
43
43
val hasAnnotation = hasVarargsAnnotation(sym)
44
44
val hasRepeatedParam = hasRepeatedParams(sym)
45
45
if hasRepeatedParam then
46
- if isJavaOverride || hasAnnotation || parentHasAnnotation(sym) then
46
+ if isJavaVarargsOverride || hasAnnotation || parentHasAnnotation(sym) then
47
47
// java varargs are more restrictive than scala's
48
48
// see https://github.com/scala/bug/issues/11714
49
49
val validJava = isValidJavaVarArgs(sym.info)
@@ -54,17 +54,17 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
54
54
|""" .stripMargin,
55
55
sym.sourcePos)
56
56
else
57
- addVarArgsForwarder(sym, isJavaOverride , hasAnnotation)
57
+ addVarArgsForwarder(sym, isJavaVarargsOverride , hasAnnotation)
58
58
else if hasAnnotation
59
59
report.error(" A method without repeated parameters cannot be annotated with @varargs" , sym.sourcePos)
60
60
end
61
61
62
62
super .transform(ref) match
63
- case ref1 : SymDenotation if ref1.is(Method ) =>
63
+ case ref1 : SymDenotation if ref1.is(Method , butNot = JavaDefined ) =>
64
64
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
68
68
// This method won't override the corresponding Java method at the end of this phase,
69
69
// only the forwarder added by `addVarArgsForwarder` will.
70
70
ref1.copySymDenotation(initFlags = ref1.flags &~ Override )
@@ -267,7 +267,6 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
267
267
return
268
268
269
269
val classInfo = owner.info
270
- val decls = classInfo.decls.cloneScope
271
270
272
271
// For simplicity we always set the varargs flag,
273
272
// although it's not strictly necessary for overrides.
@@ -280,22 +279,21 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
280
279
info = toJavaVarArgs(original.info)
281
280
).asTerm
282
281
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.
284
283
// 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 ))
289
287
}
290
- conflict match
291
- case Some ( conflict) =>
288
+ conflicts match
289
+ case conflict :: _ =>
292
290
val src =
293
291
if hasAnnotation then " @varargs"
294
292
else if isBridge then " overriding a java varargs method"
295
293
else " @varargs (on overriden method)"
296
294
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)
299
297
300
298
/** Convert type from Scala to Java varargs method */
301
299
private def toJavaVarArgs (tp : Type )(using Context ): Type = tp match
0 commit comments