Skip to content

Commit ec0f3ad

Browse files
author
dragos
committed
Partial fix for #2296: instead of VerifyError we issue a compile-time error (implementation restriction). To properly generate accessors in traits we need to move most (all?) logic related to protected accessors to phase mixin, use abstract accessors all the way up to mixin, and generate the code in the mixin class. In other words, exactly what is done for super accessors right now. Review by extempore.
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@22219 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
1 parent b814af0 commit ec0f3ad

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,15 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
411411
unit.error(pos, "Implementation restriction: " + msg)
412412
}
413413

414+
def accessibleThroughSubclassing: Boolean =
415+
(validCurrentOwner
416+
&& currentOwner.enclClass.thisSym.isSubClass(sym.owner)
417+
&& !currentOwner.enclClass.isTrait)
418+
414419
val res = /* settings.debug.value && */
415420
((sym hasFlag PROTECTED)
416421
&& !sym.owner.isPackageClass
417-
&& (!validCurrentOwner || !(currentOwner.enclClass.thisSym isSubClass sym.owner))
422+
&& !accessibleThroughSubclassing
418423
&& (enclPackage(sym.owner) != enclPackage(currentOwner))
419424
&& (enclPackage(sym.owner) == enclPackage(sym.accessBoundary(sym.owner))))
420425

@@ -424,9 +429,12 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
424429
if (host.isPackageClass) false
425430
else if (host.thisSym != host) {
426431
if (host.thisSym.tpe.typeSymbol.hasFlag(JAVA))
427-
errorRestriction(currentOwner.enclClass + " accesses protected " + sym
428-
+ " from self type " + host.thisSym.tpe)
432+
errorRestriction("%s accesses protected %s from self type %s.".format(currentOwner.enclClass, sym, host.thisSym.tpe))
429433
false
434+
} else if (host.isTrait && sym.hasFlag(JAVA)) {
435+
errorRestriction(("%s accesses protected %s inside a concrete trait method. " +
436+
"Add an accessor in a class extending %s to work around this bug.").format(currentOwner.enclClass, sym, sym.enclClass))
437+
false
430438
} else res
431439
} else res
432440
}

0 commit comments

Comments
 (0)