Skip to content

Ignore StaleSymbol exceptions when testing whether dependencies shoul… #13594

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

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dotty.tools.dotc.core.Names._
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.StdNames._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Denotations.StaleSymbol
import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.transform.SymUtils._
import dotty.tools.dotc.util.{SrcPos, NoSourcePosition}
Expand Down Expand Up @@ -340,12 +341,17 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
else DependencyByInheritance

private def ignoreDependency(sym: Symbol)(using Context) =
!sym.exists ||
sym.isAbsent(canForce = false) || // ignore dependencies that have a symbol but do not exist.
// e.g. java.lang.Object companion object
sym.isEffectiveRoot ||
sym.isAnonymousFunction ||
sym.isAnonymousClass
try
!sym.exists ||
sym.isAbsent(canForce = false) || // ignore dependencies that have a symbol but do not exist.
// e.g. java.lang.Object companion object
sym.isEffectiveRoot ||
sym.isAnonymousFunction ||
sym.isAnonymousClass
catch case ex: StaleSymbol =>
// can happen for constructor proxies. Test case is pos-macros/i13532.
true


/** Traverse the tree of a source file and record the dependencies and used names which
* can be retrieved using `dependencies` and`usedNames`.
Expand Down
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Flags._
import Names.Name
import StdNames.nme
import NameOps._
import Denotations.StaleSymbol
import util.Spans.Span
import util.{SourceFile, SourcePosition}
import transform.SymUtils._
Expand Down Expand Up @@ -241,8 +242,13 @@ class ExtractSemanticDB extends Phase:
if imported != nme.WILDCARD then
for alt <- tree.expr.tpe.member(imported).alternatives do
registerUseGuarded(None, alt.symbol, sel.imported.span, tree.source)
if (alt.symbol.companionClass.exists)
registerUseGuarded(None, alt.symbol.companionClass, sel.imported.span, tree.source)
try
if (alt.symbol.companionClass.exists)
registerUseGuarded(None, alt.symbol.companionClass, sel.imported.span, tree.source)
catch case ex: StaleSymbol =>
// can happen for constructor proxies. Test case is pos-macros/i13532.
()

case tree: Inlined =>
traverse(tree.call)
case tree: TypeTree =>
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ class Namer { typer: Typer =>
for moduleSym <- companionVals do
if moduleSym.is(Module) && !moduleSym.isDefinedInCurrentRun then
val companion =
if needsConstructorProxies(classSym) then classConstructorCompanion(classSym.asClass)
if needsConstructorProxies(classSym) then
classConstructorCompanion(classSym.asClass)
else newModuleSymbol(
ctx.owner, moduleName, EmptyFlags, EmptyFlags, (_, _) => NoType)
enterSymbol(companion)
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i13532/Bar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package testcode

import testcode.Foo

class Bar(f: Foo) {
TestMacro.call()
}
5 changes: 5 additions & 0 deletions tests/pos/i13532/Foo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package testcode

class Foo {
TestMacro.call()
}
8 changes: 8 additions & 0 deletions tests/pos/i13532/TestMacro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package testcode

import scala.quoted.Quotes

object TestMacro {
private def impl()(using Quotes) = '{ 123 }
inline def call(): Int = ${ impl() }
}