@@ -26,9 +26,6 @@ object ElimRepeated {
26
26
class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
27
27
import ast .tpd ._
28
28
29
- private val varargsAnnot = new CtxLazy (
30
- summon[Context ].requiredClass(" scala.annotation.varargs" ))
31
-
32
29
override def phaseName : String = ElimRepeated .name
33
30
34
31
override def changesMembers : Boolean = true // the phase adds vararg bridges
@@ -49,7 +46,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
49
46
50
47
private def overridesJava (sym : Symbol )(using Context ) = sym.allOverriddenSymbols.exists(_.is(JavaDefined ))
51
48
52
- private def hasVargsAnnotation (sym : Symbol )(using ctx : Context ) = sym.hasAnnotation(varargsAnnot() )
49
+ private def hasVargsAnnotation (sym : Symbol )(using ctx : Context ) = sym.hasAnnotation(defn. VarargsAnnot )
53
50
54
51
/** Eliminate repeated parameters from method types. */
55
52
private def elimRepeated (tp : Type )(using Context ): Type = tp.stripTypeVar match
@@ -120,17 +117,15 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
120
117
val isOverride = overridesJava(tree.symbol)
121
118
val hasAnnotation = hasVargsAnnotation(tree.symbol)
122
119
if tree.symbol.info.isVarArgsMethod && (isOverride || hasAnnotation) then
123
- // java varargs can be overriden by synthetic methods with an Array param,
124
- // but non-overrides need the varargs bytecode flag and cannot be synthetic
120
+ // non-overrides need the varargs bytecode flag and cannot be synthetic
125
121
// otherwise javac refuses to call them.
126
- addVarArgsBridge(tree, if hasAnnotation then JavaVarargs else Artifact )
122
+ addVarArgsBridge(tree, isOverride )
127
123
else
128
124
tree
129
125
}
130
126
131
127
/** Add a Java varargs bridge
132
- * @param ddef the original method definition which is assumed to override
133
- * a Java varargs method JM up to this phase.
128
+ * @param ddef the original method definition
134
129
* @param addFlag the flag to add to the method symbol
135
130
136
131
* @return a thicket consisting of `ddef` and a varargs bridge method
@@ -143,10 +138,12 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
143
138
* The solution is to add a "bridge" method that converts its argument from `Array[? <: T]` to `Seq[T]` and
144
139
* forwards it to `ddef`.
145
140
*/
146
- private def addVarArgsBridge (ddef : DefDef , addFlag : Flag )(using Context ): Tree =
141
+ private def addVarArgsBridge (ddef : DefDef , synthetic : Boolean )(using Context ): Tree =
147
142
val original = ddef.symbol.asTerm
143
+ // For simplicity we always set the varargs flag
144
+ val flags = ddef.symbol.flags | JavaVarargs &~ Private
148
145
val bridge = original.copy(
149
- flags = (ddef.symbol. flags | addFlag) &~ Private ,
146
+ flags = if synthetic then flags | Artifact else flags ,
150
147
info = toJavaVarArgs(ddef.symbol.info)
151
148
).enteredAfter(thisPhase).asTerm
152
149
0 commit comments