Skip to content

Commit ab3dd5b

Browse files
committed
Check if symbol was moved to a companion when bringing forward denotation
While bringing forward the denotation to a new run, check if the symbol was moved from its owner to a companion object. If so, return NoDenotation, as that denotation seems to be a leftover from pre-MoveStatics phases in a previous run.
1 parent 65a53b5 commit ab3dd5b

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Denotations.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package core
44

5-
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType, stillValid, acceptStale, traceInvalid }
5+
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType, stillValid, movedToCompanionClass, acceptStale, traceInvalid }
66
import Contexts.*
77
import Names.*
88
import NameKinds.*
@@ -755,6 +755,11 @@ object Denotations {
755755
}
756756
if (!symbol.exists) return updateValidity()
757757
if (!coveredInterval.containsPhaseId(ctx.phaseId)) return NoDenotation
758+
// Moved to companion class, likely at a later phase (in MoveStatics)
759+
this match {
760+
case symd: SymDenotation if (movedToCompanionClass(symd)) => return NoDenotation
761+
case _ =>
762+
}
758763
if (ctx.debug) traceInvalid(this)
759764
staleSymbolError
760765
}

Diff for: compiler/src/dotty/tools/dotc/core/SymDenotations.scala

+4
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,10 @@ object SymDenotations {
26802680
stillValidInOwner(denot)
26812681
}
26822682

2683+
def movedToCompanionClass(denot: SymDenotation)(using Context): Boolean =
2684+
val ownerCompanion = denot.maybeOwner.companionClass
2685+
stillValid(ownerCompanion) && ownerCompanion.unforcedDecls.contains(denot.name, denot.symbol)
2686+
26832687
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try
26842688
val owner = denot.maybeOwner.denot
26852689
stillValid(owner)

Diff for: tests/pos-macros/i21271/Macro.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted.*
2+
3+
trait Schema
4+
object Schema:
5+
lazy val sampleDate: String = "" // lazy val requried to reproduce
6+
7+
inline def derived: Schema =
8+
annotations
9+
new Schema {}
10+
11+
inline def annotations: Int = ${ annotationsImpl }
12+
def annotationsImpl(using Quotes): Expr[Int] = Expr(1)

Diff for: tests/pos-macros/i21271/Test.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val inputValueSchema = Schema.derived

0 commit comments

Comments
 (0)