From 95377aadac2826226c4954e136697b39bc50e468 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 26 Feb 2024 15:58:30 +0100 Subject: [PATCH] Avoid setting lastDenot to NoDenotation in the forward reference scenario This brings back an element of the original solution. (cherry picked from commit 5631d76f247c3d02e21eeab135b7917f30f21394) --- compiler/src/dotty/tools/dotc/core/Symbols.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 437f579ed972..4359ee4046d9 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -120,15 +120,16 @@ object Symbols { protected def recomputeDenot(lastd: SymDenotation)(using Context): SymDenotation = { util.Stats.record("Symbol.recomputeDenot") val newd = lastd.current.asInstanceOf[SymDenotation] - lastDenot = newd - if !newd.exists && lastd.initial.validFor.firstPhaseId > ctx.phaseId then + if newd.exists || lastd.initial.validFor.firstPhaseId <= ctx.phaseId then + lastDenot = newd + else // We are trying to bring forward a symbol that is defined only at a later phase // (typically, a nested Java class, invisible before erasure). - // In that case, keep the checked period to the previous validity, which - // means we will try another bring forward when the symbol is referenced - // at a later phase. Otherwise we'd get stuck on NoDenotation here. + // In that case, keep lastDenot as it was and set the checked period to lastDenot's + // previous validity, which means we will try another bring forward when the symbol + // is referenced at a later phase. Otherwise we'd get stuck on NoDenotation here. // See #15562 and test i15562b in ReplCompilerTests - checkedPeriod = lastd.initial.validFor + checkedPeriod = lastd.validFor newd }