aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/ExpandPrivate.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2015-09-09 15:34:01 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-09-09 15:34:01 +0200
commit16a3c393bd8001b7e8e2f8724f2d23279ed55bb1 (patch)
treee27a04af2ec09ff88fa274fb8524652b021d6ab3 /src/dotty/tools/dotc/transform/ExpandPrivate.scala
parentbdc0471f52491fcf9268fd369e02b1fbc5263518 (diff)
downloaddotty-16a3c393bd8001b7e8e2f8724f2d23279ed55bb1.tar.gz
dotty-16a3c393bd8001b7e8e2f8724f2d23279ed55bb1.tar.bz2
dotty-16a3c393bd8001b7e8e2f8724f2d23279ed55bb1.zip
Add postcondition to ExpandPrivate.
Check that we do not create members with weaker access than members in superclass.
Diffstat (limited to 'src/dotty/tools/dotc/transform/ExpandPrivate.scala')
-rw-r--r--src/dotty/tools/dotc/transform/ExpandPrivate.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/src/dotty/tools/dotc/transform/ExpandPrivate.scala
index dbf4456a6..bd25797be 100644
--- a/src/dotty/tools/dotc/transform/ExpandPrivate.scala
+++ b/src/dotty/tools/dotc/transform/ExpandPrivate.scala
@@ -2,6 +2,7 @@ package dotty.tools.dotc
package transform
import core._
+import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.DenotTransformers.{SymTransformer, IdentityDenotTransformer}
import Contexts.Context
import Symbols._
@@ -32,6 +33,24 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t
override def phaseName: String = "expandPrivate"
+ override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = {
+ tree match {
+ case t: DefDef =>
+ val sym = t.symbol
+ def hasWeakerAccess(other: Symbol) = {
+ // public > protected > /* default */ > private
+ if (sym.is(Private)) other.is(Private)
+ else if (sym.is(Protected)) other.is(Protected | Private)
+ else true // sym is private
+ }
+ val fail = sym.allOverriddenSymbols.findSymbol(x => !hasWeakerAccess(x))
+ if (fail.exists) {
+ assert(false, i"${sym.showFullName} has weaker access that superclass method ${fail.showFullName}")
+ }
+ case _ =>
+ }
+ }
+
/** Make private terms accessed from different classes non-private.
* Note: this happens also for accesses between class and linked module class.
* If we change the scheme at one point to make static module class computations