summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/Fields.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2016-08-19 20:01:38 -0700
committerAdriaan Moors <adriaan@lightbend.com>2016-08-29 09:54:08 +0200
commit6f7bd990ae69d6796c68894133c1975bef354e12 (patch)
treea88ac77e03434634353dee318e4648a4f6a90ce4 /src/compiler/scala/tools/nsc/transform/Fields.scala
parent0f813a5675f7f6c45acfab705b697e9cc1eceff3 (diff)
downloadscala-6f7bd990ae69d6796c68894133c1975bef354e12.tar.gz
scala-6f7bd990ae69d6796c68894133c1975bef354e12.tar.bz2
scala-6f7bd990ae69d6796c68894133c1975bef354e12.zip
Ensure access from subclass to trait lazy val
Since we need to refer to a trait lazy val's accessor using a super call in a subclass (when the field and bitmap are added), we must ensure that access is allowed. If the lazy val has an access boundary (e.g., `private[somePkg]`), make sure the `PROTECTED` flag is set, which widens access to `protected[somePkg]`. (As `member.hasAccessBoundary` implies `!member.hasFlag(PRIVATE)`, we don't have to `resetFlag PRIVATE`.)
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/Fields.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Fields.scala5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Fields.scala b/src/compiler/scala/tools/nsc/transform/Fields.scala
index 0b8705948c..cf8c25afb6 100644
--- a/src/compiler/scala/tools/nsc/transform/Fields.scala
+++ b/src/compiler/scala/tools/nsc/transform/Fields.scala
@@ -289,6 +289,11 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
// destructively mangle accessor's name (which may cause rehashing of decls), also sets flags
// this accessor has to be implemented in a subclass -- can't be private
if ((member hasFlag PRIVATE) && !fieldMemoization.constantTyped) member makeNotPrivate clazz
+ // Since we need to refer to `member` using a super call in a subclass, we must ensure that access is allowed.
+ // If `member` has an access boundary, make sure the `PROTECTED` flag is set,
+ // to widen from `private[foo]` to `protected[foo]`
+ // (note that `member.hasAccessBoundary` implies `!member.hasFlag(PRIVATE)`, so we don't have to `resetFlag PRIVATE`)
+ else if (member.isLazy && member.hasAccessBoundary) member setFlag PROTECTED
// 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.