Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not bring forward symbols created in transform and backend phases #21865

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions 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, movedToCompanionClass, acceptStale, traceInvalid }
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType, stillValid, acceptStale, traceInvalid }
import Contexts.*
import Names.*
import NameKinds.*
Expand Down Expand Up @@ -742,6 +742,8 @@ object Denotations {
* the old version otherwise.
* - If the symbol did not have a denotation that was defined at the current phase
* return a NoDenotation instead.
* - If the symbol was first defined in one of the transform phases (after pickling), it should not
* be visible in new runs, so also return a NoDenotation.
*/
private def bringForward()(using Context): SingleDenotation = {
this match {
Expand All @@ -755,11 +757,7 @@ object Denotations {
}
if (!symbol.exists) return updateValidity()
if (!coveredInterval.containsPhaseId(ctx.phaseId)) return NoDenotation
// Moved to a companion class, likely at a later phase (in MoveStatics)
this match {
case symd: SymDenotation if movedToCompanionClass(symd) => return NoDenotation
case _ =>
}
if (coveredInterval.firstPhaseId >= Phases.firstTransformPhase.id) return NoDenotation
if (ctx.debug) traceInvalid(this)
staleSymbolError
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2680,10 +2680,6 @@ 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
6 changes: 6 additions & 0 deletions tests/pos-macros/i21844/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.quoted.*

object Macro:
inline def foo = ${ fooImpl }
def fooImpl(using Quotes): Expr[Int] =
'{ 123 }
3 changes: 3 additions & 0 deletions tests/pos-macros/i21844/SubClass.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SubClass extends SuperClass
object SubClass:
val foo: Int = Macro.foo
2 changes: 2 additions & 0 deletions tests/pos-macros/i21844/SuperClassWithLazyVal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class SuperClass:
lazy val xyz: Int = 123