|
1 |
| -package dotty.tools.dotc.transform |
2 |
| - |
3 |
| -import dotty.tools.dotc.ast.desugar.{ForArtifact, PatternVar} |
4 |
| -import dotty.tools.dotc.ast.tpd.* |
5 |
| -import dotty.tools.dotc.ast.untpd, untpd.ImportSelector |
6 |
| -import dotty.tools.dotc.config.ScalaSettings |
7 |
| -import dotty.tools.dotc.core.Contexts.* |
8 |
| -import dotty.tools.dotc.core.Flags.* |
9 |
| -import dotty.tools.dotc.core.Names.{Name, SimpleName, DerivedName, TermName, termName} |
10 |
| -import dotty.tools.dotc.core.NameKinds.{ |
11 |
| - BodyRetainerName, ContextBoundParamName, ContextFunctionParamName, DefaultGetterName, WildcardParamName} |
12 |
| -import dotty.tools.dotc.core.NameOps.{isAnonymousFunctionName, isReplWrapperName, setterName} |
13 |
| -import dotty.tools.dotc.core.Scopes.newScope |
14 |
| -import dotty.tools.dotc.core.StdNames.nme |
15 |
| -import dotty.tools.dotc.core.Symbols.{ClassSymbol, NoSymbol, Symbol, defn, isDeprecated, requiredClass, requiredModule} |
16 |
| -import dotty.tools.dotc.core.Types.* |
17 |
| -import dotty.tools.dotc.report |
18 |
| -import dotty.tools.dotc.reporting.{CodeAction, UnusedSymbol} |
19 |
| -import dotty.tools.dotc.rewrites.Rewrites |
20 |
| -import dotty.tools.dotc.transform.MegaPhase.MiniPhase |
21 |
| -import dotty.tools.dotc.typer.{ImportInfo, Typer} |
22 |
| -import dotty.tools.dotc.typer.Deriving.OriginalTypeClass |
23 |
| -import dotty.tools.dotc.typer.Implicits.{ContextualImplicits, RenamedImplicitRef} |
24 |
| -import dotty.tools.dotc.util.{Property, Spans, SrcPos}, Spans.Span |
25 |
| -import dotty.tools.dotc.util.Chars.{isLineBreakChar, isWhitespace} |
26 |
| -import dotty.tools.dotc.util.chaining.* |
| 1 | +package dotty.tools.dotc |
| 2 | +package transform |
| 3 | + |
| 4 | +import ast.*, desugar.{ForArtifact, PatternVar}, tpd.*, untpd.ImportSelector |
| 5 | +import config.ScalaSettings |
| 6 | +import core.*, Contexts.*, Flags.* |
| 7 | +import Names.{Name, SimpleName, DerivedName, TermName, termName} |
| 8 | +import NameKinds.{BodyRetainerName, ContextBoundParamName, ContextFunctionParamName, DefaultGetterName, WildcardParamName} |
| 9 | +import NameOps.{isAnonymousFunctionName, isReplWrapperName, setterName} |
| 10 | +import Scopes.newScope |
| 11 | +import StdNames.nme |
| 12 | +import Symbols.{ClassSymbol, NoSymbol, Symbol, defn, isDeprecated, requiredClass, requiredModule} |
| 13 | +import Types.* |
| 14 | +import reporting.{CodeAction, UnusedSymbol} |
| 15 | +import rewrites.Rewrites |
| 16 | + |
| 17 | +import MegaPhase.MiniPhase |
| 18 | +import typer.{ImportInfo, Typer} |
| 19 | +import typer.Deriving.OriginalTypeClass |
| 20 | +import typer.Implicits.{ContextualImplicits, RenamedImplicitRef} |
| 21 | +import util.{Property, Spans, SrcPos}, Spans.Span |
| 22 | +import util.Chars.{isLineBreakChar, isWhitespace} |
| 23 | +import util.chaining.* |
27 | 24 |
|
28 | 25 | import java.util.IdentityHashMap
|
29 | 26 |
|
@@ -60,14 +57,14 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
|
60 | 57 | val resolving =
|
61 | 58 | tree.srcPos.isUserCode
|
62 | 59 | || tree.srcPos.isZeroExtentSynthetic // take as summonInline
|
63 |
| - if resolving && !ignoreTree(tree) then |
| 60 | + if !ignoreTree(tree) then |
64 | 61 | def loopOverPrefixes(prefix: Type, depth: Int): Unit =
|
65 | 62 | if depth < 10 && prefix.exists && !prefix.classSymbol.isEffectiveRoot then
|
66 |
| - resolveUsage(prefix.classSymbol, nme.NO_NAME, NoPrefix) |
| 63 | + resolveUsage(prefix.classSymbol, nme.NO_NAME, NoPrefix, imports = resolving) |
67 | 64 | loopOverPrefixes(prefix.normalizedPrefix, depth + 1)
|
68 | 65 | if tree.srcPos.isZeroExtentSynthetic then
|
69 | 66 | loopOverPrefixes(tree.typeOpt.normalizedPrefix, depth = 0)
|
70 |
| - resolveUsage(tree.symbol, tree.name, tree.typeOpt.importPrefix.skipPackageObject) |
| 67 | + resolveUsage(tree.symbol, tree.name, tree.typeOpt.importPrefix.skipPackageObject, imports = resolving) |
71 | 68 | else if tree.hasType then
|
72 | 69 | resolveUsage(tree.tpe.classSymbol, tree.name, tree.tpe.importPrefix.skipPackageObject)
|
73 | 70 | refInfos.isAssignment = false
|
@@ -318,8 +315,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
|
318 | 315 | * e.g., in `scala.Int`, `scala` is in scope for typer, but here we reverse-engineer the attribution.
|
319 | 316 | * For Select, lint does not look up `<empty>.scala` (so top-level syms look like magic) but records `scala.Int`.
|
320 | 317 | * For Ident, look-up finds the root import as usual. A competing import is OK because higher precedence.
|
| 318 | + * |
| 319 | + * The `imports` flag is whether an identifier can mark an import as used: the flag is false |
| 320 | + * for inlined code, except for `summonInline` (and related constructs) which are resolved at inlining. |
321 | 321 | */
|
322 |
| - def resolveUsage(sym0: Symbol, name: Name, prefix: Type)(using Context): Unit = |
| 322 | + def resolveUsage(sym0: Symbol, name: Name, prefix: Type, imports: Boolean = true)(using Context): Unit = |
323 | 323 | import PrecedenceLevels.*
|
324 | 324 | val sym = sym0.userSymbol
|
325 | 325 |
|
@@ -423,7 +423,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
|
423 | 423 | // record usage and possibly an import
|
424 | 424 | if !enclosed then
|
425 | 425 | refInfos.addRef(sym)
|
426 |
| - if candidate != NoContext && candidate.isImportContext && importer != null then |
| 426 | + if imports && candidate != NoContext && candidate.isImportContext && importer != null then |
427 | 427 | refInfos.sels.put(importer, ())
|
428 | 428 | end resolveUsage
|
429 | 429 |
|
|
0 commit comments