Skip to content

Commit eb1bf06

Browse files
committed
Restore inferred type is not a usage, noprefix is in import
1 parent 6c6bdd4 commit eb1bf06

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+4-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import dotty.tools.dotc.core.Denotations.SingleDenotation
1212
import dotty.tools.dotc.core.Flags.*
1313
import dotty.tools.dotc.core.Phases.Phase
1414
import dotty.tools.dotc.core.StdNames.nme
15-
import dotty.tools.dotc.core.Types.{AnnotatedType, ClassInfo, ConstantType, NamedType, NoType, TermRef, Type, TypeProxy, TypeTraverser}
15+
import dotty.tools.dotc.core.Types.{AnnotatedType, ClassInfo, ConstantType, NamedType, NoPrefix, NoType, TermRef, Type, TypeProxy, TypeTraverser}
1616
import dotty.tools.dotc.core.Flags
1717
import dotty.tools.dotc.core.Names.{Name, TermName, termName}
1818
import dotty.tools.dotc.core.NameOps.isReplWrapperName
@@ -87,14 +87,6 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
8787
ud.registerUsed(tree.symbol, name, tree.qualifier.tpe, includeForImport = tree.qualifier.span.isSynthetic, tree = tree)
8888
tree
8989

90-
override def transformApply(tree: Apply)(using Context): Tree =
91-
tree
92-
93-
override def transformTyped(tree: Typed)(using Context): Tree =
94-
tree match
95-
case Typed(expr, tpt) =>
96-
tree
97-
9890
override def transformAssign(tree: Assign)(using Context): tree.type =
9991
preparing:
10092
val sym = tree.lhs.symbol
@@ -113,12 +105,10 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
113105
transformAllDeep(tree.call)
114106
tree
115107

116-
override def prepareForTypeTree(tree: TypeTree)(using Context): Context = ctx
117-
118108
override def transformTypeTree(tree: TypeTree)(using Context): tree.type =
119109
tree.tpe match
120110
case AnnotatedType(_, annot) => transformAllDeep(annot.tree)
121-
case tpt if tpt.typeSymbol.exists =>
111+
case tpt if !tree.isInferred && tpt.typeSymbol.exists =>
122112
preparing:
123113
ud.registerUsed(tpt.typeSymbol, Some(tpt.typeSymbol.name), tree = tree) // usage was a simple name
124114
case _ =>
@@ -192,12 +182,6 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
192182
popScope(tree)
193183
tree
194184

195-
override def prepareForStats(trees: List[Tree])(using Context): Context = ctx
196-
197-
override def transformStats(trees: List[Tree])(using Context): List[Tree] =
198-
super.transformStats(trees)
199-
trees
200-
201185
override def transformOther(tree: Tree)(using Context): tree.type =
202186
preparing:
203187
tree match
@@ -377,7 +361,7 @@ object CheckUnused:
377361
* The optional name will be used to target the right import
378362
* as the same element can be imported with different renaming.
379363
*/
380-
def registerUsed(sym: Symbol, name: Option[Name], prefix: Type = NoType, includeForImport: Boolean = true, tree: Tree)(using Context): Unit =
364+
def registerUsed(sym: Symbol, name: Option[Name], prefix: Type = NoPrefix, includeForImport: Boolean = true, tree: Tree)(using Context): Unit =
381365
if sym.exists && !isConstructorOfSynth(sym) && !doNotRegister(sym) && !doNotRegisterPrefix(prefix.typeSymbol) then
382366
if sym.isConstructor then
383367
// constructors are "implicitly" imported with the class
@@ -647,7 +631,7 @@ object CheckUnused:
647631
}
648632
else
649633
!altName.exists(_.toTermName != selector.rename) && // if there is an explicit name, it must match
650-
selData.qualTpe =:= prefix && selData.allSymbolsForNamed.contains(sym)
634+
(prefix.eq(NoPrefix) || selData.qualTpe =:= prefix) && selData.allSymbolsForNamed.contains(sym)
651635
end isInImport
652636

653637
/** Annotated with @unused */

0 commit comments

Comments
 (0)