diff options
author | Martin Odersky <odersky@gmail.com> | 2014-10-19 12:02:02 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-10-26 16:24:00 +0100 |
commit | 8b38acbd349a033ba29285397fb54530a25e16e0 (patch) | |
tree | db29ba02bfd66b6e450898eedfeeb0bc1db3269d | |
parent | 979fa47ccdbdfc1f495c62b25b95ace9a637a674 (diff) | |
download | dotty-8b38acbd349a033ba29285397fb54530a25e16e0.tar.gz dotty-8b38acbd349a033ba29285397fb54530a25e16e0.tar.bz2 dotty-8b38acbd349a033ba29285397fb54530a25e16e0.zip |
Insert .package for package object references
Package object members are seen as members of the enclosing package during
typer. The normalization inserts the missing .package reference to such members.
It is necessary to satisfy a new postcondition of FirstTransform: In a selection `x.m`,
the type of `x` must derive from the owner of `m`.
-rw-r--r-- | src/dotty/tools/dotc/transform/FirstTransform.scala | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/transform/FirstTransform.scala b/src/dotty/tools/dotc/transform/FirstTransform.scala index a8cbb0595..9a1bcd7d9 100644 --- a/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -10,6 +10,8 @@ import Types._ import Constants.Constant import Contexts.Context import Symbols._ +import SymDenotations._ +import Decorators._ import scala.collection.mutable import DenotTransformers._ import typer.Checking @@ -21,6 +23,7 @@ import NameOps._ * - ensures there are companion objects for all classes except module classes * - eliminates some kinds of trees: Imports, NamedArgs, all TypTrees other than TypeTree * - converts Select/Ident/SelectFromTypeTree nodes that refer to types to TypeTrees. + * - inserts `.package` for selections of package object members * - checks the bounds of AppliedTypeTrees * - stubs out native methods */ @@ -29,6 +32,12 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer { override def phaseName = "companions" + override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = tree match { + case Select(qual, _) if tree.symbol.exists => + assert(qual.tpe derivesFrom tree.symbol.owner, i"non member selection of ${tree.symbol.showLocated} from ${qual.tpe}") + case _ => + } + /** Reorder statements so that module classes always come after their companion classes, add missing companion classes */ private def reorderAndComplete(stats: List[Tree])(implicit ctx: Context): List[Tree] = { val moduleClassDefs, singleClassDefs = mutable.Map[Name, Tree]() @@ -96,7 +105,15 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer { } override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo) = - normalizeType(tree) + normalizeType { + val qual = tree.qualifier + qual.symbol.moduleClass.denot match { + case pkg: PackageClassDenotation if tree.symbol.maybeOwner.isPackageObject => + cpy.Select(tree)(qual select pkg.packageObj.symbol, tree.name) + case _ => + tree + } + } override def transformSelectFromTypeTree(tree: SelectFromTypeTree)(implicit ctx: Context, info: TransformerInfo) = normalizeType(tree) |