Skip to content

Commit 0b92c3c

Browse files
committed
Fix accessibility case for static java members
Given ``` public class A { protected static class AI { } } public class B extends A { public static class BI extends AI { } } ``` The owner of `AI` is the module class `A$`, the owner of `BI` is the module class `B$`. When checking if the protected `AI` can be accessed in `B$`, we need to navigate from `B$` to `B`. The inheritance chain is not reflected in the module classes.
1 parent e86724e commit 0b92c3c

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,9 @@ trait Contexts { self: Analyzer =>
896896
private def isSubClassOrCompanion(sub: Symbol, base: Symbol) =
897897
sub.isNonBottomSubClass(base) ||
898898
(sub.isModuleClass && sub.linkedClassOfClass.isNonBottomSubClass(base)) ||
899-
(base.isJavaDefined && base.isModuleClass && sub.isNonBottomSubClass(base.linkedClassOfClass))
899+
(base.isJavaDefined && base.isModuleClass && (
900+
sub.isNonBottomSubClass(base.linkedClassOfClass) ||
901+
sub.isModuleClass && sub.linkedClassOfClass.isNonBottomSubClass(base.linkedClassOfClass)))
900902

901903
/** Return the closest enclosing context that defines a subclass of `clazz`
902904
* or a companion object thereof, or `NoContext` if no such context exists.

test/files/pos/t12673/A.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package compiletest.a;
2+
public class A {
3+
protected static class InnerParent { }
4+
}

test/files/pos/t12673/B.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package compiletest.b;
2+
import compiletest.a.A;
3+
4+
public class B extends A {
5+
public static class InnerChild extends InnerParent { }
6+
}

test/files/pos/t12673/Test.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package client
2+
3+
object Client {
4+
new compiletest.b.B.InnerChild
5+
}

0 commit comments

Comments
 (0)