Skip to content

Commit

Permalink
Check if symbol was moved to a companion when bringing forward denota…
Browse files Browse the repository at this point in the history
…tion

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.
  • Loading branch information
jchyb committed Sep 18, 2024
1 parent 65a53b5 commit ab3dd5b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/pos-macros/i21271/Macro.scala
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions tests/pos-macros/i21271/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val inputValueSchema = Schema.derived

0 comments on commit ab3dd5b

Please sign in to comment.