blob: 4a42523266ec374fd2b20d46ea998d130ae9d414 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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 ast.Trees._
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 treeTransformPhase = thisTransform.next
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context, info: TransformerInfo) = {
val TypeDef(_, _, Template(constr, _, _, body)) = tree
val restoredDecls = newScope
for (stat <- constr :: body)
if (stat.isInstanceOf[MemberDef] && stat.symbol.exists)
restoredDecls.enter(stat.symbol)
val cinfo = tree.symbol.asClass.classInfo
tree.symbol.copySymDenotation(
info = cinfo.derivedClassInfo( // Dotty deviation: Cannot expand cinfo inline without a type error
decls = restoredDecls: Scope)).installAfter(thisTransform)
tree
}
}
|