summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/Fields.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-06-03 17:35:14 -0700
committerAdriaan Moors <adriaan@lightbend.com>2016-08-11 10:59:18 -0700
commitf1cbe8aee820e166283c0948edede2c6b6624d01 (patch)
tree501f2fea84160965af1e906a8f2d3cfd8b143684 /src/compiler/scala/tools/nsc/transform/Fields.scala
parentfdc94676928cd9177acfcca8eb7d669e1f4eac48 (diff)
downloadscala-f1cbe8aee820e166283c0948edede2c6b6624d01.tar.gz
scala-f1cbe8aee820e166283c0948edede2c6b6624d01.tar.bz2
scala-f1cbe8aee820e166283c0948edede2c6b6624d01.zip
Make fewer trait methods not-{private, protected}
No longer making trait methods not-protected. (The backend only does public/private because of the poor mapping between visibility from Scala to the JVM). Note that protected trait members will not receive static forwarders in module classes (when mixed into objects). Historic note: we used to `makeNotPrivate` during explicitouter, now we do it later, which means more private methods must be excluded (e.g., lambdaLIFTED ones).
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/Fields.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Fields.scala18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Fields.scala b/src/compiler/scala/tools/nsc/transform/Fields.scala
index 6e064e2a24..26e517743a 100644
--- a/src/compiler/scala/tools/nsc/transform/Fields.scala
+++ b/src/compiler/scala/tools/nsc/transform/Fields.scala
@@ -249,16 +249,14 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
val accessorUnderConsideration = !(member hasFlag (DEFERRED | LAZY))
// destructively mangle accessor's name (which may cause rehashing of decls), also sets flags
- // TODO: technically, only necessary for stored fields
- if (member hasFlag PRIVATE) member makeNotPrivate clazz
-
- // Need to mark as notPROTECTED, so that it's carried over to the synthesized member in subclasses,
- // since the trait member will receive this flag later in ExplicitOuter, but the synthetic subclass member will not.
- // If we don't add notPROTECTED to the synthesized one, the member will not be seen as overriding the trait member.
- // Therefore, addForwarders's call to membersBasedOnFlags would see the deferred member in the trait,
- // instead of the concrete (desired) one in the class
- // TODO: encapsulate as makeNotProtected, similar to makeNotPrivate (also do moduleClass, e.g.)
- if (member hasFlag PROTECTED) member setFlag notPROTECTED
+ // this accessor has to be implemented in a subclass -- can't be private
+ if ((member hasFlag PRIVATE) && fieldMemoization.stored) member makeNotPrivate clazz
+
+ // This must remain in synch with publicizeTraitMethod in Mixins, so that the
+ // synthesized member in a subclass and the trait member remain in synch regarding access.
+ // Otherwise, the member will not be seen as overriding the trait member, and `addForwarders`'s call to
+ // `membersBasedOnFlags` would see the deferred member in the trait, instead of the concrete (desired) one in the class
+ // not doing: if (member hasFlag PROTECTED) member setFlag notPROTECTED
// must not reset LOCAL, as we must maintain protected[this]ness to allow that variance hole
// (not sure why this only problem only arose when we started setting the notPROTECTED flag)