Skip to content

Commit 782ee38

Browse files
committed
Do not bring forward symbols defined in transform and backend phases
1 parent ad09ab8 commit 782ee38

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 4 additions & 6 deletions
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, movedToCompanionClass, acceptStale, traceInvalid }
5+
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType, stillValid, acceptStale, traceInvalid }
66
import Contexts.*
77
import Names.*
88
import NameKinds.*
@@ -742,6 +742,8 @@ object Denotations {
742742
* the old version otherwise.
743743
* - If the symbol did not have a denotation that was defined at the current phase
744744
* return a NoDenotation instead.
745+
* - If the symbol was first defined in one of the transform phases (after pickling), it should not
746+
* be visible in new runs, so also return a NoDenotation.
745747
*/
746748
private def bringForward()(using Context): SingleDenotation = {
747749
this match {
@@ -755,11 +757,7 @@ object Denotations {
755757
}
756758
if (!symbol.exists) return updateValidity()
757759
if (!coveredInterval.containsPhaseId(ctx.phaseId)) return NoDenotation
758-
// Moved to a companion class, likely at a later phase (in MoveStatics)
759-
this match {
760-
case symd: SymDenotation if movedToCompanionClass(symd) => return NoDenotation
761-
case _ =>
762-
}
760+
if (coveredInterval.firstPhaseId >= Phases.firstTransformPhase.id) return NoDenotation
763761
if (ctx.debug) traceInvalid(this)
764762
staleSymbolError
765763
}

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,10 +2680,6 @@ 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-
26872683
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try
26882684
val owner = denot.maybeOwner.denot
26892685
stillValid(owner)

tests/pos-macros/i21844/Macro.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted.*
2+
3+
object Macro:
4+
inline def foo = ${ fooImpl }
5+
def fooImpl(using Quotes): Expr[Int] =
6+
'{ 123 }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class SubClass extends SuperClass
2+
object SubClass:
3+
val foo: Int = Macro.foo
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class SuperClass:
2+
lazy val xyz: Int = 123

0 commit comments

Comments
 (0)