In my fork of airframe surface, I have implemented a change in which I store type arguments for type aliases (both normal and opaque). The intended use is to be able to inspect type arguments of opaque type NativeArrayImpl[T] = org.mozilla.javascript.NativeArray
.
The whole thing works fine in tests, but when I publish the library and use it from my application, I get error about stale symbols:
dotty.tools.dotc.core.Denotations$StaleSymbolException: stale symbol; class xxxx#7613 in module class xxx, defined in Period(2.1-7), is referred to in run Period(3.12)
What does this mean and how can I prevent it?
The code triggering the issue is:
private def extractSymbol(t: TypeRepr) =
val dealiased = t.dealias
//println(s"dealiased ${dealiased.show} of ${t.show}")
//println(s" maybeOwner.declarations ${t.typeSymbol.maybeOwner.declarations.map(_.name).mkString(",")}")
if t != dealiased then
//println(s"dealiased as $dealiased")
surfaceOf(dealiased)
else
// t.dealias does not dealias for path dependent types, so try to find a matching inner type
val symbolInOwner = t.typeSymbol.maybeOwner.declarations.find(_.name.toString == t.typeSymbol.name.toString)
symbolInOwner match
case Some(sym) =>
//println(s"Match 1 $sym in $symbolInOwner as ${sym.typeRef.show}")
surfaceOf(sym.typeRef.dealias)
case _ =>
//println(s"Match 2 $symbolInOwner as ${t.simplified.show}")
surfaceOf(t.simplified)
private def extractTypeArgs(t: TypeRepr): Expr[Seq[Surface]] = {
//println(s"extractTypeArgs of ${t.show}: ${typeArgsOf(t).map(_.show).mkString("[", ",", "]")}")
Expr.ofSeq(typeArgsOf(t).map(s => extractSymbol(s)))
}
More complete callstack follows:
dotty.tools.dotc.core.Denotations$StaleSymbolException: stale symbol; class DynamicWalkParameters#7613 in module class anim, defined in Period(2.1-7), is referred to in run Period(3.12)
at dotty.tools.dotc.core.Denotations$SingleDenotation.staleSymbolError(Denotations.scala:963)
at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:761)
at dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:808)
at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:879)
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$.toDenot(Symbols.scala:556)
at dotty.tools.dotc.core.Substituters$.substThis(Substituters.scala:112)
at dotty.tools.dotc.core.Types$Type.substThis(Types.scala:1921)
at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeReprMethods$.memberType(QuotesImpl.scala:1871)
at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeReprMethods$.memberType(QuotesImpl.scala:1867)
at org.opengrabeso.airframe.surface.CompileTimeSurfaceFactory$Session.methodArgsOf$$anonfun$2$$anonfun$1(CompileTimeSurfaceFactory.scala:520)
at scala.collection.immutable.List.map(List.scala:251)
at org.opengrabeso.airframe.surface.CompileTimeSurfaceFactory$Session.methodArgsOf$$anonfun$2(CompileTimeSurfaceFactory.scala:520)
at scala.collection.immutable.List.map(List.scala:247)
at org.opengrabeso.airframe.surface.CompileTimeSurfaceFactory$Session.methodArgsOf(CompileTimeSurfaceFactory.scala:518)
at org.opengrabeso.airframe.surface.CompileTimeSurfaceFactory$Session.org$opengrabeso$airframe$surface$CompileTimeSurfaceFactory$Session$$methodParametersOf(CompileTimeSurfaceFactory.scala:553)