1
- package dotty .tools .dotc
1
+ package dotty .tools
2
+ package dotc
2
3
package transform
3
4
4
5
import core ._
@@ -76,7 +77,23 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
76
77
77
78
override def infoMayChange (sym : Symbol )(using Context ): Boolean = sym.is(Method )
78
79
79
- private def overridesJava (sym : Symbol )(using Context ) = sym.allOverriddenSymbols.exists(_.is(JavaDefined ))
80
+ /** Does `sym` override a symbol defined in a Java class? One might think that
81
+ * this can be expressed as
82
+ *
83
+ * sym.allOverriddenSymbols.exists(_.is(JavaDefined))
84
+ *
85
+ * but that does not work, since `allOverriddenSymbols` gets confused because the
86
+ * signatures of a Java varargs method and a Scala varargs override are not the same.
87
+ */
88
+ private def overridesJava (sym : Symbol )(using Context ) =
89
+ sym.owner.info.baseClasses.drop(1 ).exists { bc =>
90
+ bc.is(JavaDefined ) && {
91
+ val other = bc.info.nonPrivateDecl(sym.name)
92
+ other.hasAltWith { alt =>
93
+ sym.owner.thisType.memberInfo(alt.symbol).matchesLoosely(sym.info)
94
+ }
95
+ }
96
+ }
80
97
81
98
private def hasVarargsAnnotation (sym : Symbol )(using Context ) = sym.hasAnnotation(defn.VarargsAnnot )
82
99
@@ -85,7 +102,8 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
85
102
private def isVarargsMethod (sym : Symbol )(using Context ) =
86
103
hasVarargsAnnotation(sym) ||
87
104
hasRepeatedParams(sym) &&
88
- (sym.allOverriddenSymbols.exists(s => s.is(JavaDefined ) || hasVarargsAnnotation(s)))
105
+ overridesJava(sym)
106
+ || sym.allOverriddenSymbols.exists(hasVarargsAnnotation)
89
107
90
108
/** Eliminate repeated parameters from method types. */
91
109
private def elimRepeated (tp : Type , isJava : Boolean )(using Context ): Type = tp.stripTypeVar match
@@ -292,6 +310,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
292
310
report.error(s " $src produces a forwarder method that conflicts with ${conflict.showDcl}" , original.srcPos)
293
311
case Nil =>
294
312
forwarder.enteredAfter(thisPhase)
313
+ end addVarArgsForwarder
295
314
296
315
/** Convert type from Scala to Java varargs method */
297
316
private def toJavaVarArgs (tp : Type )(using Context ): Type = tp match
0 commit comments