File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -824,16 +824,16 @@ object SymDenotations {
824
824
}
825
825
826
826
/** Is protected access to target symbol permitted? */
827
- def isProtectedAccessOK = {
828
- def fail (str : => String ): Boolean = {
829
- if ( whyNot != null ) whyNot append str
827
+ def isProtectedAccessOK : Boolean =
828
+ def fail (str : => String ): false =
829
+ if whyNot != null then whyNot. append( str)
830
830
false
831
- }
832
831
val cls = owner.enclosingSubClass
833
- if (! cls.exists)
832
+ if ! cls.exists then
833
+ val encl = if ! ctx.owner.isConstructor then ctx else ctx.outersIterator.dropWhile(_.owner.isConstructor).next()
834
834
fail(
835
835
i """
836
- | Access to protected $this not permitted because enclosing ${ctx .owner.enclosingClass.showLocated}
836
+ | Access to protected $this not permitted because enclosing ${encl .owner.enclosingClass.showLocated}
837
837
| is not a subclass of ${owner.showLocated} where target is defined """ )
838
838
else if
839
839
! ( isType // allow accesses to types from arbitrary subclasses fixes #4737
@@ -847,7 +847,7 @@ object SymDenotations {
847
847
| Access to protected ${symbol.show} not permitted because prefix type ${pre.widen.show}
848
848
| does not conform to ${cls.showLocated} where the access takes place """ )
849
849
else true
850
- }
850
+ end isProtectedAccessOK
851
851
852
852
if pre eq NoPrefix then true
853
853
else if isAbsent() then false
Original file line number Diff line number Diff line change
1
+ -- Error: tests/neg/i7709.scala:5:20 -----------------------------------------------------------------------------------
2
+ 5 | class B extends X.Y // error
3
+ | ^^^
4
+ | class Y in object X cannot be accessed as a member of X.type from class B.
5
+ | Access to protected class Y not permitted because enclosing object A
6
+ | is not a subclass of object X where target is defined
7
+ -- Error: tests/neg/i7709.scala:10:18 ----------------------------------------------------------------------------------
8
+ 10 | def y = new xx.Y // error
9
+ | ^^^^
10
+ | class Y cannot be accessed as a member of XX from class C.
11
+ | Access to protected class Y not permitted because enclosing class C
12
+ | is not a subclass of class XX where target is defined
Original file line number Diff line number Diff line change
1
+
2
+ object X :
3
+ protected class Y
4
+ object A :
5
+ class B extends X .Y // error
6
+ class XX :
7
+ protected class Y
8
+ class C :
9
+ def xx = new XX
10
+ def y = new xx.Y // error
11
+ class YY extends XX :
12
+ def y = new Y
You can’t perform that action at this time.
0 commit comments