@@ -811,22 +811,38 @@ object Symbols {
811811 val ttmap1 = ttmap.withSubstitution(originals, copies)
812812 originals.lazyZip(copies) foreach { (original, copy) =>
813813 val odenot = original.denot
814- val oinfo = original.info match {
815- case ClassInfo (pre, _, parents, decls, selfInfo) =>
816- assert(original.isClass)
817- ClassInfo (pre, copy.asClass, parents, decls.cloneScope, selfInfo)
818- case oinfo => oinfo
819- }
814+ val completer = new LazyType :
815+
816+ def complete (denot : SymDenotation )(using Context ): Unit =
817+
818+ val oinfo = original.info match
819+ case ClassInfo (pre, _, parents, decls, selfInfo) =>
820+ assert(original.isClass)
821+ val otypeParams = original.typeParams
822+ if otypeParams.isEmpty then
823+ ClassInfo (pre, copy.asClass, parents, decls.cloneScope, selfInfo)
824+ else
825+ // copy type params, enter other definitions unchanged
826+ // type parameters need to be copied early, since other type
827+ // computations depend on them.
828+ val decls1 = newScope
829+ val newTypeParams = mapSymbols(original.typeParams, ttmap1, mapAlways = true )
830+ newTypeParams.foreach(decls1.enter)
831+ for sym <- decls do if ! sym.is(TypeParam ) then decls1.enter(sym)
832+ val parents1 = parents.map(_.substSym(otypeParams, newTypeParams))
833+ val selfInfo1 = selfInfo match
834+ case selfInfo : Type => selfInfo.substSym(otypeParams, newTypeParams)
835+ case _ => selfInfo
836+ ClassInfo (pre, copy.asClass, parents1, decls1, selfInfo1)
837+ case oinfo => oinfo
820838
821- val completer = new LazyType {
822- def complete (denot : SymDenotation )(using Context ): Unit = {
823839 denot.info = oinfo // needed as otherwise we won't be able to go from Sym -> parents & etc
824840 // Note that this is a hack, but hack commonly used in Dotty
825841 // The same thing is done by other completers all the time
826842 denot.info = ttmap1.mapType(oinfo)
827843 denot.annotations = odenot.annotations.mapConserve(ttmap1.apply)
828- }
829- }
844+
845+ end completer
830846
831847 copy.denot = odenot.copySymDenotation(
832848 symbol = copy,
0 commit comments