From 0c8e129c2c7cdaced48bbc836ce1cbdbb9620b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Wed, 22 Jun 2022 13:40:11 +0200 Subject: [PATCH 1/2] Do not complain about overriding classes in .java source files. --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 0d93e83432fe..662ec838b899 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -527,7 +527,7 @@ object Checking { fail("Traits cannot have secondary constructors" + addendum) checkApplicable(Inline, sym.isTerm && !sym.isOneOf(Mutable | Module)) checkApplicable(Lazy, !sym.isOneOf(Method | Mutable)) - if (sym.isType && !sym.is(Deferred)) + if (sym.isType && !sym.isOneOf(Deferred | JavaDefined)) for (cls <- sym.allOverriddenSymbols.filter(_.isClass)) { fail(CannotHaveSameNameAs(sym, cls, CannotHaveSameNameAs.CannotBeOverridden)) sym.setFlag(Private) // break the overriding relationship by making sym Private From cf21a07e7b4c1d2d6d2cb1a0b3e2c33b5934f952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Wed, 22 Jun 2022 13:54:22 +0200 Subject: [PATCH 2/2] Fix #15199: Exclude JavaDefined Modules from bridge generation. JavaDefined modules are imaginary symbols that dotc uses to refer to static methods of Java classes. They have no reification, and therefore it makes no sense for them to participate in bridge generation. --- compiler/src/dotty/tools/dotc/transform/Bridges.scala | 2 +- tests/run/i15199/Child_1.java | 4 ++++ tests/run/i15199/Parent_1.java | 4 ++++ tests/run/i15199/Test_2.scala | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/run/i15199/Child_1.java create mode 100644 tests/run/i15199/Parent_1.java create mode 100644 tests/run/i15199/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Bridges.scala b/compiler/src/dotty/tools/dotc/transform/Bridges.scala index 071109147b45..e302170991f9 100644 --- a/compiler/src/dotty/tools/dotc/transform/Bridges.scala +++ b/compiler/src/dotty/tools/dotc/transform/Bridges.scala @@ -37,7 +37,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) { override def parents = Array(root.superClass) override def exclude(sym: Symbol) = - !sym.isOneOf(MethodOrModule) || super.exclude(sym) + !sym.isOneOf(MethodOrModule) || sym.isAllOf(Module | JavaDefined) || super.exclude(sym) override def canBeHandledByParent(sym1: Symbol, sym2: Symbol, parent: Symbol): Boolean = OverridingPairs.isOverridingPair(sym1, sym2, parent.thisType) diff --git a/tests/run/i15199/Child_1.java b/tests/run/i15199/Child_1.java new file mode 100644 index 000000000000..f66dcc55279c --- /dev/null +++ b/tests/run/i15199/Child_1.java @@ -0,0 +1,4 @@ +public class Child_1 extends Parent_1 { + public class Inner { + } +} diff --git a/tests/run/i15199/Parent_1.java b/tests/run/i15199/Parent_1.java new file mode 100644 index 000000000000..529c9780a308 --- /dev/null +++ b/tests/run/i15199/Parent_1.java @@ -0,0 +1,4 @@ +public class Parent_1 { + public class Inner { + } +} diff --git a/tests/run/i15199/Test_2.scala b/tests/run/i15199/Test_2.scala new file mode 100644 index 000000000000..9684d6fb2655 --- /dev/null +++ b/tests/run/i15199/Test_2.scala @@ -0,0 +1,5 @@ +class ScalaChild extends Child_1 + +@main def Test(): Unit = + val methods = classOf[ScalaChild].getDeclaredMethods() + assert(methods.length == 0, methods.mkString(", "))