Skip to content

Commit cbaa827

Browse files
authored
Merge pull request #3868 from dotty-staging/fix-#3721
Fix #3721: Roll back SubstMap functionality into general TreeTypeMap
2 parents 50f9cfa + 81c80a5 commit cbaa827

File tree

2 files changed

+5
-39
lines changed

2 files changed

+5
-39
lines changed

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Types._, Contexts._, Constants._, Names._, Flags._
77
import SymDenotations._, Symbols._, Annotations._, Trees._, Symbols._
88
import Denotations._, Decorators._
99
import dotty.tools.dotc.transform.SymUtils._
10+
import core.tasty.TreePickler.Hole
1011

1112
/** A map that applies three functions and a substitution together to a tree and
1213
* makes sure they are coordinated so that the result is well-typed. The functions are
@@ -115,6 +116,8 @@ class TreeTypeMap(
115116
val guard1 = tmap.transform(guard)
116117
val rhs1 = tmap.transform(rhs)
117118
cpy.CaseDef(cdef)(pat1, guard1, rhs1)
119+
case Hole(n, args) =>
120+
Hole(n, args.mapConserve(transform)).withPos(tree.pos).withType(mapType(tree.tpe))
118121
case tree1 =>
119122
super.transform(tree1)
120123
}
@@ -154,7 +157,7 @@ class TreeTypeMap(
154157
assert(!to.exists(substFrom contains _))
155158
assert(!from.exists(newOwners contains _))
156159
assert(!to.exists(oldOwners contains _))
157-
newMap(
160+
new TreeTypeMap(
158161
typeMap,
159162
treeMap,
160163
from ++ oldOwners,
@@ -163,16 +166,6 @@ class TreeTypeMap(
163166
to ++ substTo)
164167
}
165168

166-
/** A new map of the same class this one */
167-
protected def newMap(
168-
typeMap: Type => Type,
169-
treeMap: Tree => Tree,
170-
oldOwners: List[Symbol],
171-
newOwners: List[Symbol],
172-
substFrom: List[Symbol],
173-
substTo: List[Symbol])(implicit ctx: Context) =
174-
new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
175-
176169
/** Apply `typeMap` and `ownerMap` to given symbols `syms`
177170
* and return a treemap that contains the substitution
178171
* between original and mapped symbols.

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
4242
var enteredSyms: List[Symbol] = Nil
4343
}
4444

45-
/** A tree substituter that also works for holes */
46-
class SubstMap(
47-
typeMap: Type => Type = IdentityTypeMap,
48-
treeMap: Tree => Tree = identity _,
49-
oldOwners: List[Symbol] = Nil,
50-
newOwners: List[Symbol] = Nil,
51-
substFrom: List[Symbol],
52-
substTo: List[Symbol])(implicit ctx: Context)
53-
extends TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo) {
54-
55-
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
56-
case Hole(n, args) =>
57-
Hole(n, args.mapConserve(transform)).withPos(tree.pos).withType(mapType(tree.tpe))
58-
case _ =>
59-
super.transform(tree)
60-
}
61-
62-
override def newMap(
63-
typeMap: Type => Type,
64-
treeMap: Tree => Tree,
65-
oldOwners: List[Symbol],
66-
newOwners: List[Symbol],
67-
substFrom: List[Symbol],
68-
substTo: List[Symbol])(implicit ctx: Context) =
69-
new SubstMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
70-
}
71-
7245
/** Requiring that `paramRefs` consists of a single reference `seq` to a Seq[Any],
7346
* a tree map that replaces each hole with index `n` with `seq(n)`, applied
7447
* to any arguments in the hole.
@@ -148,7 +121,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
148121
}
149122
importedTags.clear()
150123
Block(typeDefs,
151-
new SubstMap(substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
124+
new TreeTypeMap(substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
152125
.apply(expr))
153126
}
154127

0 commit comments

Comments
 (0)