File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
compiler/src/dotty/tools/dotc/transform
tests/run/i17021.ext-java Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ object ProtectedAccessors {
3838 sym.isTerm && sym.is(Protected ) &&
3939 ! sym.owner.is(Trait ) && // trait methods need to be handled specially, are currently always public
4040 ! insideBoundaryOf(sym) &&
41- ! ctx.owner.enclosingClass.derivesFrom(sym.owner)
41+ (sym.is( JavaDefined ) || ! ctx.owner.enclosingClass.derivesFrom(sym.owner) )
4242}
4343
4444class ProtectedAccessors extends MiniPhase {
Original file line number Diff line number Diff line change 1+ // Derives from run/i17021.defs, but with a Java protected member
2+ package p1 ;
3+
4+ public class A {
5+ protected int foo () { return 1 ; }
6+ }
Original file line number Diff line number Diff line change 1+ // Derives from run/i17021.defs
2+ // but with a Java protected member
3+ // which changes the behaviour
4+ package p2:
5+ trait B extends p1.A :
6+ def bar : Int = foo
7+
8+ class C extends B :
9+ override def foo : Int = 2
10+
11+ object Test :
12+ def main (args : Array [String ]): Unit =
13+ val n = new p2.C ().bar
14+ assert(n == 1 , n) // B can only call super.foo
You can’t perform that action at this time.
0 commit comments