Skip to content

Commit 5c253a6

Browse files
smarterodersky
authored andcommitted
Fix needsProtectedAccessor check
A protected accessor is not needed if the current class self-type is a subtype of the accessed symbol, but the logic to check this was broken before this commit and looked at the host class self-type instead.
1 parent 12eeb69 commit 5c253a6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,8 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
300300
private def needsProtectedAccessor(sym: Symbol, pos: Position)(implicit ctx: Context): Boolean = {
301301
val clazz = currentClass
302302
val host = hostForAccessorOf(sym, clazz)
303-
val selfType = host.classInfo.selfType
304303
def accessibleThroughSubclassing =
305-
validCurrentClass && (selfType <:< sym.owner.typeRef) && !clazz.is(Trait)
304+
validCurrentClass && (clazz.classInfo.selfType <:< sym.owner.typeRef) && !clazz.is(Trait)
306305

307306
val isCandidate = (
308307
sym.is(Protected)
@@ -312,9 +311,11 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
312311
&& (sym.enclosingPackageClass != currentClass.enclosingPackageClass)
313312
&& (sym.enclosingPackageClass == sym.accessBoundary(sym.enclosingPackageClass))
314313
)
315-
def isSelfType = !(host.typeRef <:< selfType) && {
316-
if (selfType.typeSymbol.is(JavaDefined))
317-
ctx.restrictionError(s"cannot accesses protected $sym from within $clazz with self type $selfType", pos)
314+
val hostSelfType = host.classInfo.selfType
315+
def isSelfType = !(host.typeRef <:< hostSelfType) && {
316+
if (hostSelfType.typeSymbol.is(JavaDefined))
317+
ctx.restrictionError(
318+
s"cannot accesses protected $sym from within $clazz with host self type $hostSelfType", pos)
318319
true
319320
}
320321
def isJavaProtected = host.is(Trait) && sym.is(JavaDefined) && {

0 commit comments

Comments
 (0)