@@ -21,6 +21,9 @@ import Decorators.*
2121 * @param newOwners New owners, replacing previous owners.
2222 * @param substFrom The symbols that need to be substituted.
2323 * @param substTo The substitution targets.
24+ * @param cpy A tree copier that is used to create new trees.
25+ * @param alwaysCopySymbols If set, symbols are always copied, even when they
26+ * are not impacted by the transformation.
2427 *
2528 * The reason the substitution is broken out from the rest of the type map is
2629 * that all symbols have to be substituted at the same time. If we do not do this,
@@ -38,7 +41,9 @@ class TreeTypeMap(
3841 val newOwners : List [Symbol ] = Nil ,
3942 val substFrom : List [Symbol ] = Nil ,
4043 val substTo : List [Symbol ] = Nil ,
41- cpy : tpd.TreeCopier = tpd.cpy)(using Context ) extends tpd.TreeMap (cpy) {
44+ cpy : tpd.TreeCopier = tpd.cpy,
45+ alwaysCopySymbols : Boolean = false ,
46+ )(using Context ) extends tpd.TreeMap (cpy) {
4247 import tpd .*
4348
4449 def copy (
@@ -48,7 +53,7 @@ class TreeTypeMap(
4853 newOwners : List [Symbol ],
4954 substFrom : List [Symbol ],
5055 substTo : List [Symbol ])(using Context ): TreeTypeMap =
51- new TreeTypeMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
56+ new TreeTypeMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols )
5257
5358 /** If `sym` is one of `oldOwners`, replace by corresponding symbol in `newOwners` */
5459 def mapOwner (sym : Symbol ): Symbol = sym.subst(oldOwners, newOwners)
@@ -202,7 +207,7 @@ class TreeTypeMap(
202207 * between original and mapped symbols.
203208 */
204209 def withMappedSyms (syms : List [Symbol ]): TreeTypeMap =
205- withMappedSyms(syms, mapSymbols(syms, this ))
210+ withMappedSyms(syms, mapSymbols(syms, this , mapAlways = alwaysCopySymbols ))
206211
207212 /** The tree map with the substitution between originals `syms`
208213 * and mapped symbols `mapped`. Also goes into mapped classes
@@ -224,6 +229,10 @@ class TreeTypeMap(
224229 tmap1
225230 }
226231
232+ def withAlwaysCopySymbols : TreeTypeMap =
233+ if alwaysCopySymbols then this
234+ else new TreeTypeMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols = true )
235+
227236 override def toString =
228237 def showSyms (syms : List [Symbol ]) =
229238 syms.map(sym => s " $sym# ${sym.id}" ).mkString(" , " )
0 commit comments