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

Stale symbol when calling a macro in companion object when superclass has a lazy val #21844

Open
prolativ opened this issue Oct 25, 2024 · 2 comments · May be fixed by #21865
Open

Stale symbol when calling a macro in companion object when superclass has a lazy val #21844

prolativ opened this issue Oct 25, 2024 · 2 comments · May be fixed by #21865
Assignees
Labels
area:inline area:metaprogramming:quotes Issues related to quotes and splices itype:bug itype:crash regression This worked in a previous version but doesn't anymore

Comments

@prolativ
Copy link
Contributor

Compiler version

Failing: 3.3.0, and later, including 3.3.4, 3.5.2, 3.6.1, 3.6.2-RC1-bin-20241023-31e7359-NIGHTLY
Used to work in 3.2.0

Minimized code

import scala.quoted.*

object Macro:
  inline def foo = ${ fooImpl }
  def fooImpl(using Quotes): Expr[Int] =
    '{ 123 }
class SuperClass:
  lazy val xyz: Int = 123
class SubClass extends SuperClass
object SubClass:
  val foo: Int = Macro.foo

Output (click arrow to expand)

dotty.tools.dotc.core.Denotations$StaleSymbolException: stale symbol; method xyz$lzyINIT1#23578 in class SuperClass, defined in Period(2.78-95), is referred to in run Period(3.94)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.staleSymbolError(Denotations.scala:966)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:764)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:811)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:882)
        at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:124)
        at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:118)
        at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:109)
        at dotty.tools.dotc.core.Symbols$Symbol.name(Symbols.scala:277)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMemberNames$$anonfun$2(SymDenotations.scala:2373)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:619)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:617)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1303)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMemberNames(SymDenotations.scala:2373)
        at dotty.tools.dotc.core.SymDenotations$MemberNamesImpl.apply(SymDenotations.scala:2962)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.memberNames(SymDenotations.scala:2355)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMemberNames$$anonfun$1(SymDenotations.scala:2365)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMemberNames(SymDenotations.scala:2362)
        at dotty.tools.dotc.core.SymDenotations$MemberNamesImpl.apply(SymDenotations.scala:2962)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.memberNames(SymDenotations.scala:2355)
        at dotty.tools.dotc.core.Types$Type.memberNames(Types.scala:997)
        at dotty.tools.dotc.core.Types$Type.memberDenots(Types.scala:1014)
        at dotty.tools.dotc.core.Types$Type.allMembers(Types.scala:1109)
        at dotty.tools.backend.jvm.BCodeHelpers$BCForwardersGen.conflictingNames$lzyINIT1$1(BCodeHelpers.scala:489)
        at dotty.tools.backend.jvm.BCodeHelpers$BCForwardersGen.conflictingNames$1(BCodeHelpers.scala:490)
        at dotty.tools.backend.jvm.BCodeHelpers$BCForwardersGen.addForwarders$$anonfun$3(BCodeHelpers.scala:499)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.backend.jvm.BCodeHelpers$BCForwardersGen.addForwarders(BCodeHelpers.scala:493)
        at dotty.tools.backend.jvm.BCodeHelpers$BCForwardersGen.addForwarders$(BCodeHelpers.scala:410)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.addForwarders(BCodeSkelBuilder.scala:134)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.initJClass(BCodeSkelBuilder.scala:362)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:183)
        at dotty.tools.backend.jvm.CodeGen.genClass(CodeGen.scala:160)
        at dotty.tools.backend.jvm.CodeGen.genClassDef$1(CodeGen.scala:62)
        at dotty.tools.backend.jvm.CodeGen.genClassDefs$1(CodeGen.scala:117)
        at dotty.tools.backend.jvm.CodeGen.genClassDefs$1$$anonfun$1(CodeGen.scala:115)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.backend.jvm.CodeGen.genClassDefs$1(CodeGen.scala:115)
        at dotty.tools.backend.jvm.CodeGen.genUnit(CodeGen.scala:120)
        at dotty.tools.backend.jvm.GenBCode.run(GenBCode.scala:90)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:380)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:373)
        at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:98)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:383)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:395)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:395)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:288)
        at dotty.tools.dotc.Run.compileSuspendedUnits(Run.scala:409)
        at dotty.tools.dotc.Driver.finish(Driver.scala:63)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
        at dotty.tools.dotc.Driver.process(Driver.scala:201)
        at dotty.tools.dotc.Driver.process(Driver.scala:169)
        at dotty.tools.dotc.Driver.process(Driver.scala:181)
        at dotty.tools.dotc.Driver.main(Driver.scala:211)
        at dotty.tools.dotc.Main.main(Main.scala)
Error while emitting /private/tmp/repro/SubClass.scala
stale symbol; method xyz$lzyINIT1#23578 in class SuperClass, defined in Period(2.78-95), is referred to in run Period(3.94)
1 error found
Compilation failed
@prolativ prolativ added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label regression This worked in a previous version but doesn't anymore labels Oct 25, 2024
@prolativ
Copy link
Contributor Author

Also, the problem occurs only if the sources are compiled together at the same time. If we compile the sources without SubClass first and then just SubClass, everything compiles fine

@Gedochao Gedochao added area:inline area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 28, 2024
@jchyb
Copy link
Contributor

jchyb commented Oct 28, 2024

This looks related to #21271, but that regression was introduced later, in 3.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:inline area:metaprogramming:quotes Issues related to quotes and splices itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants