Skip to content

Commit 9fdeb94

Browse files
Fix #6152: dotc requires override to implement abstract java method
The reason is that bridges are allowed to participate in overriding relationships. This commit does the same scalac does, that is, prevent bridges from participation in such relationships. This is applied in all cases except from when bridges are generated: bridges are allowed to override other bridges. This is necessary to support abstract overrides where such bridges are generated when type parameters are involved in the return types of the overridden method.
1 parent 24946d8 commit 9fdeb94

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileConstants.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ object ClassfileConstants {
341341
case JAVA_ACC_PRIVATE => Private
342342
case JAVA_ACC_PROTECTED => Protected
343343
case JAVA_ACC_FINAL => Final
344-
case JAVA_ACC_SYNTHETIC => Synthetic
344+
case JAVA_ACC_SYNTHETIC => Synthetic | Artifact
345345
case JAVA_ACC_STATIC => JavaStatic
346346
case JAVA_ACC_ABSTRACT => if (isClass) Abstract else Deferred
347347
case JAVA_ACC_INTERFACE => PureInterfaceCreationFlags | JavaDefined

compiler/src/dotty/tools/dotc/transform/Bridges.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
1919
private val preErasureCtx = ctx.withPhase(ctx.erasurePhase)
2020
private val elimErasedCtx = ctx.withPhase(ctx.elimErasedValueTypePhase.next)
2121

22-
private class BridgesCursor(implicit ctx: Context) extends OverridingPairs.Cursor(root) {
22+
private class BridgesCursor(implicit ctx: Context) extends OverridingPairs.Cursor(root, excludeArtifacts = false) {
2323

2424
/** Only use the superclass of `root` as a parent class. This means
2525
* overriding pairs that have a common implementation in a trait parent

compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ object OverridingPairs {
2020
/** The cursor class
2121
* @param base the base class that contains the overriding pairs
2222
*/
23-
class Cursor(base: Symbol)(implicit ctx: Context) {
23+
class Cursor(base: Symbol, excludeArtifacts: Boolean = true)(implicit ctx: Context) {
2424

2525
private val self = base.thisType
2626

2727
/** Symbols to exclude: Here these are constructors and private locals.
2828
* But it may be refined in subclasses.
2929
*/
30-
protected def exclude(sym: Symbol): Boolean = !sym.memberCanMatchInheritedSymbols
30+
protected def exclude(sym: Symbol): Boolean =
31+
!sym.memberCanMatchInheritedSymbols || (excludeArtifacts && sym.is(Artifact))
3132

3233
/** The parents of base that are checked when deciding whether an overriding
3334
* pair has already been treated in a parent class.

tests/pos/i6152/A_1.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
abstract class A {
2+
public abstract Object f();
3+
4+
public static abstract class B extends A {
5+
@Override
6+
public abstract String f();
7+
}
8+
}

tests/pos/i6152/Test_2.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class C extends A.B {
2+
def f() = "hello"
3+
}
4+
5+
object Main extends App {
6+
val c: A = new C
7+
println(c.f())
8+
}

0 commit comments

Comments
 (0)