From 2b55f0e660735f69a90bef9e843cc3415491c330 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Thu, 26 Jun 2025 13:02:58 +0200 Subject: [PATCH] Fix Symbol.info remapping in TreeTypeMap Previously, the map would first copy and remap the outermost symbols, then inner declarations, then ddeclarations of those declarations etc., so if an outer symbol referred to a more nested one, that reference was not remapped, causing issues later. [Cherry-picked e57d743430f583336fa4ce6e9159717f4843b55f] --- .../dotty/tools/dotc/ast/TreeTypeMap.scala | 5 ++++ tests/run/i23279.scala | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/run/i23279.scala diff --git a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala index 5ddbdd990182..0298c306d24d 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -224,6 +224,11 @@ class TreeTypeMap( val tmap1 = tmap.withMappedSyms( origCls(cls).typeParams ::: origDcls, cls.typeParams ::: mappedDcls) + mapped.foreach { sym => + // outer Symbols can reference nested ones in info, + // so we remap that once again with the updated TreeTypeMap + sym.info = tmap1.mapType(sym.info) + } origDcls.lazyZip(mappedDcls).foreach(cls.asClass.replace) tmap1 } diff --git a/tests/run/i23279.scala b/tests/run/i23279.scala new file mode 100644 index 000000000000..8774e5afcd79 --- /dev/null +++ b/tests/run/i23279.scala @@ -0,0 +1,28 @@ +inline def simpleInlineWrap(f: => Any): Unit = f + +@main def Test(): Unit = { + simpleInlineWrap { + object lifecycle { + object Lifecycle { + trait FromZIO + } + } + object defn { + val Lifecycle: lifecycle.Lifecycle.type = lifecycle.Lifecycle + } + val xa: defn.Lifecycle.type = defn.Lifecycle + } + + // more nested case + simpleInlineWrap { + object lifecycle { + object Lifecycle { + object FromZIO + } + } + object defn { + val Lifecycle: lifecycle.Lifecycle.type = lifecycle.Lifecycle + } + val xa: defn.Lifecycle.FromZIO.type = defn.Lifecycle.FromZIO + } +}