@@ -2,6 +2,7 @@ package dotty.tools
22package dotc
33package ast
44
5+ import dotty .tools .dotc .transform .ExplicitOuter
56import dotty .tools .dotc .typer .ProtoTypes .FunProtoTyped
67import transform .SymUtils ._
78import core ._
@@ -243,6 +244,17 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
243244 ta.assignType(untpd.TypeDef (cls.name, impl), cls)
244245 }
245246
247+ // { <label> def while$(): Unit = if (cond) { body; while$() } ; while$() }
248+ def WhileDo (owner : Symbol , cond : Tree , body : List [Tree ])(implicit ctx : Context ): Tree = {
249+ val sym = ctx.newSymbol(owner, nme.WHILE_PREFIX , Flags .Label | Flags .Synthetic ,
250+ MethodType (Nil , defn.UnitType ), coord = cond.pos)
251+
252+ val call = Apply (ref(sym), Nil )
253+ val rhs = If (cond, Block (body, call), unitLiteral)
254+ Block (List (DefDef (sym, rhs)), call)
255+ }
256+
257+
246258 def Import (expr : Tree , selectors : List [untpd.Tree ])(implicit ctx : Context ): Import =
247259 ta.assignType(untpd.Import (expr, selectors), ctx.newImportSymbol(ctx.owner, expr))
248260
@@ -288,7 +300,16 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
288300 if (tp.isType) TypeTree (tp)
289301 else if (prefixIsElidable(tp)) Ident (tp)
290302 else tp.prefix match {
291- case pre : SingletonType => singleton(pre).select(tp)
303+ case pre : SingletonType =>
304+ val prefix =
305+ singleton(pre) match {
306+ case t : This if ctx.erasedTypes && ! (t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
307+ // after erasure outer paths should be respected
308+ new ExplicitOuter .OuterOps (ctx).path(t.tpe.widen.classSymbol)
309+ case t =>
310+ t
311+ }
312+ prefix.select(tp)
292313 case pre => SelectFromTypeTree (TypeTree (pre), tp)
293314 } // no checks necessary
294315
@@ -563,7 +584,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
563584 loop(from.owner, from :: froms, to :: tos)
564585 else {
565586 // println(i"change owner ${from :: froms}%, % ==> $tos of $tree")
566- new TreeTypeMap (oldOwners = from :: froms, newOwners = tos).apply(tree)
587+ new TreeTypeMap (oldOwners = from :: froms, newOwners = tos)(ctx.withMode( Mode . FutureDefsOK )) .apply(tree)
567588 }
568589 }
569590 loop(from, Nil , to :: Nil )
@@ -578,8 +599,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
578599 def traverse (tree : Tree )(implicit ctx : Context ) = tree match {
579600 case tree : DefTree =>
580601 val sym = tree.symbol
581- if (sym.denot(ctx.withPhase(trans)).owner == from)
582- sym.copySymDenotation(owner = to).installAfter(trans)
602+ if (sym.denot(ctx.withPhase(trans)).owner == from) {
603+ val d = sym.copySymDenotation(owner = to)
604+ d.installAfter(trans)
605+ d.transformAfter(trans, d => if (d.owner eq from) d.copySymDenotation(owner = to) else d)
606+ }
583607 if (sym.isWeakOwner) traverseChildren(tree)
584608 case _ =>
585609 traverseChildren(tree)
0 commit comments