diff options
5 files changed, 30 insertions, 6 deletions
diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index 1d319242b..f413fc902 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -48,9 +48,9 @@ class Compiler { List(new Pickler), // Generate TASTY info List(new FirstTransform, // Some transformations to put trees into a canonical form new CheckReentrant), // Internal use only: Check that compiled program has no data races involving global vars - List(new RefChecks, // Various checks mostly related to abstract members and overriding - new CheckStatic, // Check restrictions that apply to @static members + List(new CheckStatic, // Check restrictions that apply to @static members new ElimRepeated, // Rewrite vararg parameters and arguments + new RefChecks, // Various checks mostly related to abstract members and overriding new NormalizeFlags, // Rewrite some definition flags new ExtensionMethods, // Expand methods of value classes with extension methods new ExpandSAMs, // Expand single abstract method closures to anonymous classes diff --git a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala index 258b7f234..d955628e3 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala @@ -32,8 +32,21 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer with Annotati def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = elimRepeated(tp) + + override def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = + super.transform(ref) match { + case ref1: SymDenotation if (ref1 ne ref) && overridesJava(ref1.symbol) => + // This method won't override the corresponding Java method at the end of this phase, + // only the bridge added by `addVarArgsBridge` will. + ref1.copySymDenotation(initFlags = ref1.flags &~ Override) + case ref1 => + ref1 + } + override def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = sym is Method + private def overridesJava(sym: Symbol)(implicit ctx: Context) = sym.allOverriddenSymbols.exists(_ is JavaDefined) + private def elimRepeated(tp: Type)(implicit ctx: Context): Type = tp.stripTypeVar match { case tp @ MethodType(paramNames, paramTypes) => val resultType1 = elimRepeated(tp.resultType) @@ -93,10 +106,9 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer with Annotati */ override def transformDefDef(tree: DefDef)(implicit ctx: Context, info: TransformerInfo): Tree = { assert(ctx.phase == thisTransformer) - def overridesJava = tree.symbol.allOverriddenSymbols.exists(_ is JavaDefined) - if (tree.symbol.info.isVarArgsMethod && overridesJava) - addVarArgsBridge(tree)(ctx.withPhase(thisTransformer.next)) - else + if (tree.symbol.info.isVarArgsMethod && overridesJava(tree.symbol)) + addVarArgsBridge(tree) + else tree } @@ -120,6 +132,7 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer with Annotati .appliedToArgs(vrefs :+ TreeGen.wrapArray(varArgRef, elemtp)) .appliedToArgss(vrefss1) }) + Thicket(ddef, bridgeDef) } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 23d05e087..e8ff7d572 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -766,6 +766,9 @@ class RefChecks extends MiniPhase { thisTransformer => override def phaseName: String = "refchecks" + // Needs to run after ElimRepeated for override checks involving varargs methods + override def runsAfter = Set(classOf[ElimRepeated]) + val treeTransform = new Transform(NoLevelInfo) class Transform(currentLevel: RefChecks.OptLevelInfo = RefChecks.NoLevelInfo) extends TreeTransform { diff --git a/tests/pos-java-interop/varargsOverride/Base.java b/tests/pos-java-interop/varargsOverride/Base.java new file mode 100644 index 000000000..a4607b71c --- /dev/null +++ b/tests/pos-java-interop/varargsOverride/Base.java @@ -0,0 +1,5 @@ +class Base { + public Object foo(Object... x) { + return x; + } +} diff --git a/tests/pos-java-interop/varargsOverride/Sub.scala b/tests/pos-java-interop/varargsOverride/Sub.scala new file mode 100644 index 000000000..9d3e2bf0d --- /dev/null +++ b/tests/pos-java-interop/varargsOverride/Sub.scala @@ -0,0 +1,3 @@ +class Sub extends Base { + override def foo(x: Object*): Object = x +} |