Skip to content

Commit fd1a1c3

Browse files
committed
TODO: makeNotPrivate in explicitOuter???
this messes with finding the setter for a getter in a trait, as somehow the getter is made not-private, but not the setter... we'll try another approach: link setters & getters symbolically using the referenced field -- what could possibly go wrong?
1 parent 4f12b6d commit fd1a1c3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ abstract class ExplicitOuter extends InfoTransform
157157
if (hasOuterField(clazz)) //2
158158
decls1 enter newOuterField(clazz)
159159
}
160-
if (!clazz.isTrait && !parents.isEmpty) {
160+
if (!clazz.isTrait && !parents.isEmpty) { // 4
161161
for (mc <- clazz.mixinClasses) {
162162
val mixinOuterAcc: Symbol = exitingExplicitOuter(outerAccessor(mc))
163163
if (mixinOuterAcc != NoSymbol) {
@@ -264,7 +264,12 @@ abstract class ExplicitOuter extends InfoTransform
264264
}
265265
}
266266

267-
/** <p>
267+
/** TODO: Revise this.... We shouldn't use makeNotPrivate until all subsequent phases are able to resolve symbolically
268+
* (e.g., if we name mangle a getter, we can no longer look up the setter unless its name is also name mangled)
269+
* We also shouldn't be messing with privacy that's unrelated to outer accessors.
270+
* Since traits are now compiled to java interfaces, protected has the same applicability as for classes.
271+
*
272+
* <p>
268273
* The phase performs the following transformations on terms:
269274
* </p>
270275
* <ol>
@@ -411,8 +416,12 @@ abstract class ExplicitOuter extends InfoTransform
411416
else atPos(tree.pos)(outerPath(outerValue, currentClass.outerClass, sym)) // (5)
412417

413418
case Select(qual, name) =>
414-
// make not private symbol accessed from inner classes, as well as
419+
// TODO: move this to the end of the pipeline, as it breaks member lookup
420+
// (e.g., getter <> setter correlation is by name, but we could use the referenced field for that...?)
421+
//
422+
// symbols accessed from inner classes, as well as
415423
// symbols accessed from @inline methods
424+
// are made not-private (name mangling to emulate privacy)
416425
//
417426
// See SI-6552 for an example of why `sym.owner.enclMethod hasAnnotation ScalaInlineClass`
418427
// is not suitable; if we make a method-local class non-private, it mangles outer pointer names.
@@ -422,10 +431,12 @@ abstract class ExplicitOuter extends InfoTransform
422431
if ((currentClass != sym.owner || enclMethodIsInline) && !sym.isMethodWithExtension)
423432
sym.makeNotPrivate(sym.owner)
424433

425-
val qsym = qual.tpe.widen.typeSymbol
426-
if (sym.isProtected && //(4)
427-
(qsym.isTrait || !(qual.isInstanceOf[Super] || (qsym isSubClass currentClass))))
434+
//(4)
435+
if (sym.isProtected &&
436+
!qual.isInstanceOf[Super] &&
437+
!(qual.tpe.widen.typeSymbol isSubClass currentClass))
428438
sym setFlag notPROTECTED
439+
429440
super.transform(tree)
430441

431442
case Apply(sel @ Select(qual, nme.CONSTRUCTOR), args) if isInner(sel.symbol.owner) =>

0 commit comments

Comments
 (0)