@@ -3,7 +3,7 @@ package dotc
33package ast
44
55import core ._
6- import Types ._ , Contexts ._
6+ import Types ._ , Contexts ._ , Flags . _
77import Symbols ._ , Annotations ._ , Trees ._ , Symbols ._ , Constants .Constant
88import Decorators ._
99import dotty .tools .dotc .transform .SymUtils ._
@@ -178,25 +178,25 @@ class TreeTypeMap(
178178 * and return a treemap that contains the substitution
179179 * between original and mapped symbols.
180180 */
181- def withMappedSyms (syms : List [Symbol ], mapAlways : Boolean = false ): TreeTypeMap =
182- withMappedSyms(syms, mapSymbols(syms, this , mapAlways ))
181+ def withMappedSyms (syms : List [Symbol ]): TreeTypeMap =
182+ withMappedSyms(syms, mapSymbols(syms, this ))
183183
184184 /** The tree map with the substitution between originals `syms`
185185 * and mapped symbols `mapped`. Also goes into mapped classes
186186 * and substitutes their declarations.
187187 */
188- def withMappedSyms (syms : List [Symbol ], mapped : List [Symbol ]): TreeTypeMap = {
189- val symsChanged = syms ne mapped
190- val substMap = withSubstitution(syms, mapped)
191- val fullMap = mapped.filter(_.isClass).foldLeft(substMap) { (tmap, cls) =>
192- val origDcls = cls.info.decls.toList
193- val mappedDcls = mapSymbols(origDcls, tmap)
194- val tmap1 = tmap.withMappedSyms(origDcls, mappedDcls)
195- if (symsChanged)
188+ def withMappedSyms (syms : List [Symbol ], mapped : List [Symbol ]): TreeTypeMap =
189+ if syms eq mapped then this
190+ else
191+ val substMap = withSubstitution(syms, mapped)
192+ lazy val origCls = mapped.zip(syms).filter(_._1.isClass).toMap
193+ mapped.filter(_.isClass).foldLeft(substMap) { (tmap, cls) =>
194+ val origDcls = cls.info.decls.toList.filterNot(_.is(TypeParam ))
195+ val mappedDcls = mapSymbols(origDcls, tmap, mapAlways = true )
196+ val tmap1 = tmap.withMappedSyms(
197+ origCls(cls).typeParams ::: origDcls,
198+ cls.typeParams ::: mappedDcls)
196199 origDcls.lazyZip(mappedDcls).foreach(cls.asClass.replace)
197- tmap1
198- }
199- if (symsChanged || (fullMap eq substMap)) fullMap
200- else withMappedSyms(syms, mapAlways = true )
201- }
200+ tmap1
201+ }
202202}
0 commit comments