File tree 4 files changed +28
-5
lines changed
compiler/src/dotty/tools/dotc
4 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -1154,10 +1154,10 @@ object SymDenotations {
1154
1154
final def enclosingClass (using Context ): Symbol = {
1155
1155
def enclClass (sym : Symbol , skip : Boolean ): Symbol = {
1156
1156
def newSkip = sym.is(JavaStaticTerm )
1157
- if ( ! sym.exists)
1157
+ if ! sym.exists then
1158
1158
NoSymbol
1159
- else if ( sym.isClass)
1160
- if ( skip) enclClass(sym.owner, newSkip) else sym
1159
+ else if sym.isClass then
1160
+ if skip || sym.isRefinementClass then enclClass(sym.owner, newSkip) else sym
1161
1161
else
1162
1162
enclClass(sym.owner, skip || newSkip)
1163
1163
}
Original file line number Diff line number Diff line change @@ -44,7 +44,10 @@ object ProtectedAccessors {
44
44
/** Do we need a protected accessor for accessing sym from the current context's owner? */
45
45
def needsAccessor (sym : Symbol )(using Context ): Boolean =
46
46
needsAccessorIfNotInSubclass(sym) &&
47
- ! ctx.owner.enclosingClass.derivesFrom(sym.owner)
47
+ ! needsAccessorIsSubclass(sym)
48
+
49
+ def needsAccessorIsSubclass (sym : Symbol )(using Context ): Boolean =
50
+ ctx.owner.enclosingClass.derivesFrom(sym.owner)
48
51
}
49
52
50
53
class ProtectedAccessors extends MiniPhase {
Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ class SuperAccessors(thisPhase: DenotTransformer) {
195
195
* Otherwise, we need to go through an accessor,
196
196
* which the implementing class will provide an implementation for.
197
197
*/
198
- if ctx.owner.enclosingClass.derivesFrom (sym.owner ) then
198
+ if ProtectedAccessors .needsAccessorIsSubclass (sym) then
199
199
if sym.is(JavaDefined ) then
200
200
report.error(em " ${ctx.owner} accesses protected $sym inside a concrete trait method: use super. ${sel.name} instead " , sel.srcPos)
201
201
sel
Original file line number Diff line number Diff line change
1
+ package object packer : // the super class needs to be in a different package
2
+ class SuperClass ():
3
+ protected val problem : Any = ??? // needs to be protected
4
+
5
+ class SuperClass ():
6
+ protected val problem : Any = ??? // needs to be protected
7
+
8
+ // type Target = SuperClass // passes
9
+ type Target = packer.SuperClass // error
10
+
11
+ trait Child extends Target :
12
+
13
+ val aliased : problem.type = problem
14
+ type Alias = problem.type
15
+
16
+ val newProblem : Any {val prog : problem.type } = ??? // error
17
+ val newProblem2 : Any {val prog : Alias } = ??? // passes
18
+ val newProblem3 : Any {val prog : aliased.type } = ??? // passes
19
+
20
+ class ChildImpl extends Target with Child // concrete implementation is needed
You can’t perform that action at this time.
0 commit comments