Skip to content

Commit abcc58b

Browse files
authored
Merge pull request #13594 from dotty-staging/fix-13532
Ignore StaleSymbol exceptions when testing whether dependencies shoul…
2 parents bbbbfc0 + 1a70a69 commit abcc58b

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

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

Lines changed: 12 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,17 @@ 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+
// can happen for constructor proxies. Test case is pos-macros/i13532.
353+
true
354+
349355

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

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Flags._
1313
import Names.Name
1414
import StdNames.nme
1515
import NameOps._
16+
import Denotations.StaleSymbol
1617
import util.Spans.Span
1718
import util.{SourceFile, SourcePosition}
1819
import transform.SymUtils._
@@ -241,8 +242,13 @@ class ExtractSemanticDB extends Phase:
241242
if imported != nme.WILDCARD then
242243
for alt <- tree.expr.tpe.member(imported).alternatives do
243244
registerUseGuarded(None, alt.symbol, sel.imported.span, tree.source)
244-
if (alt.symbol.companionClass.exists)
245-
registerUseGuarded(None, alt.symbol.companionClass, sel.imported.span, tree.source)
245+
try
246+
if (alt.symbol.companionClass.exists)
247+
registerUseGuarded(None, alt.symbol.companionClass, sel.imported.span, tree.source)
248+
catch case ex: StaleSymbol =>
249+
// can happen for constructor proxies. Test case is pos-macros/i13532.
250+
()
251+
246252
case tree: Inlined =>
247253
traverse(tree.call)
248254
case tree: TypeTree =>

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@ class Namer { typer: Typer =>
691691
for moduleSym <- companionVals do
692692
if moduleSym.is(Module) && !moduleSym.isDefinedInCurrentRun then
693693
val companion =
694-
if needsConstructorProxies(classSym) then classConstructorCompanion(classSym.asClass)
694+
if needsConstructorProxies(classSym) then
695+
classConstructorCompanion(classSym.asClass)
695696
else newModuleSymbol(
696697
ctx.owner, moduleName, EmptyFlags, EmptyFlags, (_, _) => NoType)
697698
enterSymbol(companion)

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)