Skip to content

Commit f6ffe67

Browse files
committed
Simplify TreeTypeMap#withMappedSyms
1 parent 7c542fc commit f6ffe67

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,19 @@ class TreeTypeMap(
187187
*/
188188
def withMappedSyms(syms: List[Symbol], mapped: List[Symbol]): TreeTypeMap = {
189189
val symsChanged = syms ne mapped
190-
val origTypeParams = syms.filter(_.isClass).flatMap(_.typeParams)
191-
val mappedTypeParams = mapped.filter(_.isClass).flatMap(_.typeParams)
192-
assert(origTypeParams.hasSameLengthAs(mappedTypeParams))
193-
val substMap = withSubstitution(syms ++ origTypeParams, mapped ++ mappedTypeParams)
190+
val substMap = withSubstitution(syms, mapped)
191+
lazy val origCls = mapped.zip(syms).filter(_._1.isClass).toMap
194192
val fullMap = mapped.filter(_.isClass).foldLeft(substMap) { (tmap, cls) =>
195193
val origDcls = cls.info.decls.toList.filterNot(_.is(TypeParam))
196194
val mappedDcls = mapSymbols(origDcls, tmap)
197-
// type parameters were already copied in the `mapSymbols` call which produced `mapped`.
198-
val tmap1 = tmap
199-
// .withSubstitution(origTypeParams, cls.typeParams)
200-
// type parameters were already mapped in the `mapSymbols` call which produced `mapped`.
201-
.withMappedSyms(origDcls, mappedDcls)
202-
if (symsChanged)
195+
val tmap1 = tmap.withMappedSyms(
196+
origCls(cls).typeParams ::: origDcls,
197+
cls.typeParams ::: mappedDcls)
198+
if symsChanged then
203199
origDcls.lazyZip(mappedDcls).foreach(cls.asClass.replace)
204200
tmap1
205201
}
206-
if (symsChanged || (fullMap eq substMap)) fullMap
202+
if symsChanged || (fullMap eq substMap) then fullMap
207203
else withMappedSyms(syms, mapAlways = true)
208204
}
209205
}

0 commit comments

Comments
 (0)