blob: 3a168b1fe52dee9200c8d81702097d1b761f3a42 (
plain) (
tree)
|
|
package dotty.tools.dotc
package transform
import core._
import DenotTransformers.IdentityDenotTransformer
import Contexts.Context
import Symbols._
import Scopes._
import collection.mutable
import TreeTransforms.MiniPhaseTransform
import SymDenotations._
import ast.Trees._
import NameOps._
import typer.Mode
import TreeTransforms.TransformerInfo
/** The preceding lambda lift and flatten phases move symbols to different scopes
* and rename them. This miniphase cleans up afterwards and makes sure that all
* class scopes contain the symbols defined in them.
*/
class RestoreScopes extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
import ast.tpd._
override def phaseName = "restoreScopes"
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context, info: TransformerInfo) = {
val TypeDef(_, impl: Template) = tree
//
val restoredDecls = newScope
for (stat <- impl.constr :: impl.body)
if (stat.isInstanceOf[MemberDef] && stat.symbol.exists)
restoredDecls.enter(stat.symbol)
// Enter class in enclosing package scope, in case it was an inner class before flatten.
// For top-level classes this does nothing.
val cls = tree.symbol.asClass
val pkg = cls.owner.asClass
pkg.enter(cls)
val cinfo = cls.classInfo
tree.symbol.copySymDenotation(
info = cinfo.derivedClassInfo( // Dotty deviation: Cannot expand cinfo inline without a type error
decls = restoredDecls: Scope)).installAfter(thisTransform)
tree
}
}
|