diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 2418aba1978b..5907df832e36 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -2,7 +2,7 @@ package dotty.tools package dotc package core -import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType, stillValid, acceptStale, traceInvalid } +import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType, stillValid, movedToCompanionClass, acceptStale, traceInvalid } import Contexts.* import Names.* import NameKinds.* @@ -755,6 +755,11 @@ object Denotations { } if (!symbol.exists) return updateValidity() if (!coveredInterval.containsPhaseId(ctx.phaseId)) return NoDenotation + // Moved to companion class, likely at a later phase (in MoveStatics) + this match { + case symd: SymDenotation if (movedToCompanionClass(symd)) => return NoDenotation + case _ => + } if (ctx.debug) traceInvalid(this) staleSymbolError } diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 3904228756a0..906e74735097 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -2680,6 +2680,10 @@ object SymDenotations { stillValidInOwner(denot) } + def movedToCompanionClass(denot: SymDenotation)(using Context): Boolean = + val ownerCompanion = denot.maybeOwner.companionClass + stillValid(ownerCompanion) && ownerCompanion.unforcedDecls.contains(denot.name, denot.symbol) + private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try val owner = denot.maybeOwner.denot stillValid(owner) diff --git a/tests/pos-macros/i21271/Macro.scala b/tests/pos-macros/i21271/Macro.scala new file mode 100644 index 000000000000..09d29ecc65af --- /dev/null +++ b/tests/pos-macros/i21271/Macro.scala @@ -0,0 +1,12 @@ +import scala.quoted.* + +trait Schema +object Schema: + lazy val sampleDate: String = "" // lazy val requried to reproduce + + inline def derived: Schema = + annotations + new Schema {} + +inline def annotations: Int = ${ annotationsImpl } +def annotationsImpl(using Quotes): Expr[Int] = Expr(1) diff --git a/tests/pos-macros/i21271/Test.scala b/tests/pos-macros/i21271/Test.scala new file mode 100644 index 000000000000..c0ba38212b09 --- /dev/null +++ b/tests/pos-macros/i21271/Test.scala @@ -0,0 +1 @@ +val inputValueSchema = Schema.derived