Skip to content

Commit d38cbde

Browse files
committed
Ignore StaleSymbol exceptions when testing whether dependencies should be ignored
Fixes #13532 A question is whether the catch should be in `ignoreDependency` in the SBT dependency extractor or in `isAbsent` itself. I put it in `ignoreDependency` for now in order not to hide possible stale symbol errors since isAbsent is called quite often.
1 parent 1a84caa commit d38cbde

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import dotty.tools.dotc.core.Names._
1414
import dotty.tools.dotc.core.Phases._
1515
import dotty.tools.dotc.core.StdNames._
1616
import dotty.tools.dotc.core.Symbols._
17+
import dotty.tools.dotc.core.Denotations.StaleSymbol
1718
import dotty.tools.dotc.core.Types._
1819
import dotty.tools.dotc.transform.SymUtils._
1920
import dotty.tools.dotc.util.{SrcPos, NoSourcePosition}
@@ -340,12 +341,16 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
340341
else DependencyByInheritance
341342

342343
private def ignoreDependency(sym: Symbol)(using Context) =
343-
!sym.exists ||
344-
sym.isAbsent(canForce = false) || // ignore dependencies that have a symbol but do not exist.
345-
// e.g. java.lang.Object companion object
346-
sym.isEffectiveRoot ||
347-
sym.isAnonymousFunction ||
348-
sym.isAnonymousClass
344+
try
345+
!sym.exists ||
346+
sym.isAbsent(canForce = false) || // ignore dependencies that have a symbol but do not exist.
347+
// e.g. java.lang.Object companion object
348+
sym.isEffectiveRoot ||
349+
sym.isAnonymousFunction ||
350+
sym.isAnonymousClass
351+
catch case ex: StaleSymbol =>
352+
true
353+
349354

350355
/** Traverse the tree of a source file and record the dependencies and used names which
351356
* can be retrieved using `dependencies` and`usedNames`.

tests/pos/i13532/Bar.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package testcode
2+
3+
import testcode.Foo
4+
5+
class Bar(f: Foo) {
6+
TestMacro.call()
7+
}

tests/pos/i13532/Foo.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package testcode
2+
3+
class Foo {
4+
TestMacro.call()
5+
}

tests/pos/i13532/TestMacro.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package testcode
2+
3+
import scala.quoted.Quotes
4+
5+
object TestMacro {
6+
private def impl()(using Quotes) = '{ 123 }
7+
inline def call(): Int = ${ impl() }
8+
}

0 commit comments

Comments
 (0)