Skip to content

Commit

Permalink
Fix #6152: dotc requires override to implement abstract java method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anatoliykmetyuk committed May 20, 2019
1 parent 24946d8 commit 9fdeb94
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ object ClassfileConstants {
case JAVA_ACC_PRIVATE => Private
case JAVA_ACC_PROTECTED => Protected
case JAVA_ACC_FINAL => Final
case JAVA_ACC_SYNTHETIC => Synthetic
case JAVA_ACC_SYNTHETIC => Synthetic | Artifact
case JAVA_ACC_STATIC => JavaStatic
case JAVA_ACC_ABSTRACT => if (isClass) Abstract else Deferred
case JAVA_ACC_INTERFACE => PureInterfaceCreationFlags | JavaDefined
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Bridges.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
private val preErasureCtx = ctx.withPhase(ctx.erasurePhase)
private val elimErasedCtx = ctx.withPhase(ctx.elimErasedValueTypePhase.next)

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

/** Only use the superclass of `root` as a parent class. This means
* overriding pairs that have a common implementation in a trait parent
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ object OverridingPairs {
/** The cursor class
* @param base the base class that contains the overriding pairs
*/
class Cursor(base: Symbol)(implicit ctx: Context) {
class Cursor(base: Symbol, excludeArtifacts: Boolean = true)(implicit ctx: Context) {

private val self = base.thisType

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

/** The parents of base that are checked when deciding whether an overriding
* pair has already been treated in a parent class.
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i6152/A_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
abstract class A {
public abstract Object f();

public static abstract class B extends A {
@Override
public abstract String f();
}
}
8 changes: 8 additions & 0 deletions tests/pos/i6152/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class C extends A.B {
def f() = "hello"
}

object Main extends App {
val c: A = new C
println(c.f())
}

0 comments on commit 9fdeb94

Please sign in to comment.