|
1 | | -package dotty.tools.dotc.transform |
| 1 | +package dotty.tools.dotc |
| 2 | +package transform |
2 | 3 |
|
3 | 4 | import dotty.tools.dotc.ast.desugar.{ForArtifact, PatternVar} |
4 | 5 | import dotty.tools.dotc.ast.tpd.* |
@@ -60,14 +61,14 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha |
60 | 61 | val resolving = |
61 | 62 | tree.srcPos.isUserCode |
62 | 63 | || tree.srcPos.isZeroExtentSynthetic // take as summonInline |
63 | | - if resolving && !ignoreTree(tree) then |
| 64 | + if !ignoreTree(tree) then |
64 | 65 | def loopOverPrefixes(prefix: Type, depth: Int): Unit = |
65 | 66 | if depth < 10 && prefix.exists && !prefix.classSymbol.isEffectiveRoot then |
66 | | - resolveUsage(prefix.classSymbol, nme.NO_NAME, NoPrefix) |
| 67 | + resolveUsage(prefix.classSymbol, nme.NO_NAME, NoPrefix, imports = resolving) |
67 | 68 | loopOverPrefixes(prefix.normalizedPrefix, depth + 1) |
68 | 69 | if tree.srcPos.isZeroExtentSynthetic then |
69 | 70 | loopOverPrefixes(tree.typeOpt.normalizedPrefix, depth = 0) |
70 | | - resolveUsage(tree.symbol, tree.name, tree.typeOpt.importPrefix.skipPackageObject) |
| 71 | + resolveUsage(tree.symbol, tree.name, tree.typeOpt.importPrefix.skipPackageObject, imports = resolving) |
71 | 72 | else if tree.hasType then |
72 | 73 | resolveUsage(tree.tpe.classSymbol, tree.name, tree.tpe.importPrefix.skipPackageObject) |
73 | 74 | refInfos.isAssignment = false |
@@ -286,8 +287,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha |
286 | 287 | * e.g., in `scala.Int`, `scala` is in scope for typer, but here we reverse-engineer the attribution. |
287 | 288 | * For Select, lint does not look up `<empty>.scala` (so top-level syms look like magic) but records `scala.Int`. |
288 | 289 | * For Ident, look-up finds the root import as usual. A competing import is OK because higher precedence. |
| 290 | + * |
| 291 | + * The `imports` flag is whether an identifier can mark an import as used: the flag is false |
| 292 | + * for inlined code, except for `summonInline` (and related constructs) which are resolved at inlining. |
289 | 293 | */ |
290 | | - def resolveUsage(sym0: Symbol, name: Name, prefix: Type)(using Context): Unit = |
| 294 | + def resolveUsage(sym0: Symbol, name: Name, prefix: Type, imports: Boolean = true)(using Context): Unit = |
291 | 295 | import PrecedenceLevels.* |
292 | 296 | val sym = sym0.userSymbol |
293 | 297 |
|
@@ -391,7 +395,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha |
391 | 395 | // record usage and possibly an import |
392 | 396 | if !enclosed then |
393 | 397 | refInfos.addRef(sym) |
394 | | - if candidate != NoContext && candidate.isImportContext && importer != null then |
| 398 | + if imports && candidate != NoContext && candidate.isImportContext && importer != null then |
395 | 399 | refInfos.sels.put(importer, ()) |
396 | 400 | end resolveUsage |
397 | 401 |
|
|
0 commit comments