aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/untpd.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-15 12:08:42 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-02 16:12:28 +0200
commitb5132e87afe1a98467369d2f91ba4483a6a88ea4 (patch)
treef8fca34ccef6c3b9ff5d9d7f971f30aabd84a2e1 /src/dotty/tools/dotc/ast/untpd.scala
parent84bc770bb7bcac2fe09a13c62c24aac1e3fda582 (diff)
downloaddotty-b5132e87afe1a98467369d2f91ba4483a6a88ea4.tar.gz
dotty-b5132e87afe1a98467369d2f91ba4483a6a88ea4.tar.bz2
dotty-b5132e87afe1a98467369d2f91ba4483a6a88ea4.zip
Change owner as necessary when typing a TypedSplice
When typing an untpd.TypedSplice it could be that the owner at the time the tree is originally typed is different from the owner at the time the tree is unwrapped. In that case the owner needs to be changed. Problem was noticed in Course-2002-02 after changing Closure to be a pure expression. This means that TypedSplices containing closures are no longer lifted out from containing closures during eta expansion, and the owner chain got corrupted.
Diffstat (limited to 'src/dotty/tools/dotc/ast/untpd.scala')
-rw-r--r--src/dotty/tools/dotc/ast/untpd.scala11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala
index 114c13684..a0a353c13 100644
--- a/src/dotty/tools/dotc/ast/untpd.scala
+++ b/src/dotty/tools/dotc/ast/untpd.scala
@@ -21,10 +21,15 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
}
/** A typed subtree of an untyped tree needs to be wrapped in a TypedSlice */
- case class TypedSplice(tree: tpd.Tree) extends ProxyTree {
+ abstract case class TypedSplice(tree: tpd.Tree)(val owner: Symbol) extends ProxyTree {
def forwardTo = tree
}
+ object TypedSplice {
+ def apply(tree: tpd.Tree)(implicit ctx: Context): TypedSplice =
+ new TypedSplice(tree)(ctx.owner) {}
+ }
+
/** mods object name impl */
case class ModuleDef(name: TermName, impl: Template)
extends MemberDef {
@@ -232,7 +237,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
case AppliedTypeTree(tycon, targs) =>
(tycon, targs)
case TypedSplice(AppliedTypeTree(tycon, targs)) =>
- (TypedSplice(tycon), targs map TypedSplice)
+ (TypedSplice(tycon), targs map (TypedSplice(_)))
case TypedSplice(tpt1: Tree) =>
val argTypes = tpt1.tpe.argTypes
val tycon = tpt1.tpe.withoutArgs(argTypes)
@@ -260,7 +265,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def AppliedTypeTree(tpt: Tree, arg: Tree): AppliedTypeTree =
AppliedTypeTree(tpt, arg :: Nil)
- def TypeTree(tpe: Type): TypedSplice = TypedSplice(TypeTree().withTypeUnchecked(tpe))
+ def TypeTree(tpe: Type)(implicit ctx: Context): TypedSplice = TypedSplice(TypeTree().withTypeUnchecked(tpe))
def TypeDef(name: TypeName, tparams: List[TypeDef], rhs: Tree): TypeDef =
if (tparams.isEmpty) TypeDef(name, rhs) else new PolyTypeDef(name, tparams, rhs)