From 6a7b6b0fbb5c365f59ac47b6f8e09cdc839e7d66 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 28 May 2021 11:51:01 +0200 Subject: [PATCH] Map parents of local classes in TreeTypeMap Fix mapping of parents of local classes in TreeTypeMap Fies #12632 --- compiler/src/dotty/tools/dotc/core/Symbols.scala | 7 ++++--- tests/pos/i12632.scala | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i12632.scala diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index d8e107852947..58097b1891f1 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -818,9 +818,10 @@ object Symbols { val oinfo = original.info match case ClassInfo(pre, _, parents, decls, selfInfo) => assert(original.isClass) + val parents1 = parents.mapConserve(ttmap.mapType) val otypeParams = original.typeParams if otypeParams.isEmpty then - ClassInfo(pre, copy.asClass, parents, decls.cloneScope, selfInfo) + ClassInfo(pre, copy.asClass, parents1, decls.cloneScope, selfInfo) else // copy type params, enter other definitions unchanged // type parameters need to be copied early, since other type @@ -829,11 +830,11 @@ object Symbols { val newTypeParams = mapSymbols(original.typeParams, ttmap1, mapAlways = true) newTypeParams.foreach(decls1.enter) for sym <- decls do if !sym.is(TypeParam) then decls1.enter(sym) - val parents1 = parents.map(_.substSym(otypeParams, newTypeParams)) + val parents2 = parents1.map(_.substSym(otypeParams, newTypeParams)) val selfInfo1 = selfInfo match case selfInfo: Type => selfInfo.substSym(otypeParams, newTypeParams) case _ => selfInfo - ClassInfo(pre, copy.asClass, parents1, decls1, selfInfo1) + ClassInfo(pre, copy.asClass, parents2, decls1, selfInfo1) case oinfo => oinfo denot.info = oinfo // needed as otherwise we won't be able to go from Sym -> parents & etc diff --git a/tests/pos/i12632.scala b/tests/pos/i12632.scala new file mode 100644 index 000000000000..c17a4324486a --- /dev/null +++ b/tests/pos/i12632.scala @@ -0,0 +1,10 @@ +class CCC[S](val i: Int) { + def this() = + this( + { + val z = new Ordering[S] { + override def compare(x: S, y: S): Int = ??? + } + 3 + }) +}