aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/tpd.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-09-25 13:25:06 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-10-11 06:38:11 +0200
commit543ff7f4123ded7172fd6ede59f09945efd7c158 (patch)
tree1c14165b391ca2b6de15f5a584fc804474ada13e /src/dotty/tools/dotc/ast/tpd.scala
parent167581469779cabc7138427d506a16507369cbf5 (diff)
downloaddotty-543ff7f4123ded7172fd6ede59f09945efd7c158.tar.gz
dotty-543ff7f4123ded7172fd6ede59f09945efd7c158.tar.bz2
dotty-543ff7f4123ded7172fd6ede59f09945efd7c158.zip
Make changeOwner more robust regarding non-standard owner chains
The problem is running changeOwner(from, to) where - from is a ValDef or a Label - an embedded definition has as owner not `from` but some owner of `from`. We allow such denomrlaized owners and the pattern matcher generates them. This patch makes changeOwner take these situations into account.
Diffstat (limited to 'src/dotty/tools/dotc/ast/tpd.scala')
-rw-r--r--src/dotty/tools/dotc/ast/tpd.scala15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala
index 101631738..e4450da89 100644
--- a/src/dotty/tools/dotc/ast/tpd.scala
+++ b/src/dotty/tools/dotc/ast/tpd.scala
@@ -525,8 +525,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def subst(from: List[Symbol], to: List[Symbol])(implicit ctx: Context): ThisTree =
new TreeTypeMap(substFrom = from, substTo = to).apply(tree)
- def changeOwner(from: Symbol, to: Symbol)(implicit ctx: Context): ThisTree =
- new TreeTypeMap(oldOwners = from :: Nil, newOwners = to :: Nil).apply(tree)
+ /** Change owner from `from` to `to`. If `from` is a weak owner, also change its
+ * owner to `to`, and continue until a non-weak owner is reached.
+ */
+ def changeOwner(from: Symbol, to: Symbol)(implicit ctx: Context): ThisTree = {
+ def loop(from: Symbol, froms: List[Symbol], tos: List[Symbol]): ThisTree = {
+ if (from.isWeakOwner) loop(from.owner, from :: froms, to :: tos)
+ else {
+ //println(i"change owner ${from :: froms}%, % ==> $tos of $tree")
+ new TreeTypeMap(oldOwners = from :: froms, newOwners = tos).apply(tree)
+ }
+ }
+ loop(from, Nil, to :: Nil)
+ }
def select(name: Name)(implicit ctx: Context): Select =
Select(tree, name)