Skip to content

Commit 1133e42

Browse files
committed
TypeTree is usage of simple name
1 parent f089c91 commit 1133e42

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
118118
override def transformTypeTree(tree: TypeTree)(using Context): tree.type =
119119
tree.tpe match
120120
case AnnotatedType(_, annot) => transformAllDeep(annot.tree)
121+
case tpt if tpt.typeSymbol.exists =>
122+
preparing:
123+
ud.registerUsed(tpt.typeSymbol, Some(tpt.typeSymbol.name), tree = tree) // usage was a simple name
121124
case _ =>
122125
tree
123126

@@ -405,6 +408,7 @@ object CheckUnused:
405408
!languageImport(imp.expr).nonEmpty
406409
&& !imp.isGeneratedByEnum
407410
&& !isTransparentAndInline(imp)
411+
&& !doNotRegisterPrefix(imp.expr.tpe.typeSymbol)
408412
&& peekScopeType != ScopeType.ReplWrapper // #18383 Do not report top-level import's in the repl as unused
409413
then
410414
val qualTpe = imp.expr.tpe

tests/warn/i19657.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,28 @@ import scala.annotation.meta.*
8888
object Alias {
8989
type A = Deprecated @param
9090
}
91+
92+
// avoid reporting on runtime (nothing to do with transparent inline)
93+
import scala.runtime.EnumValue
94+
95+
trait Lime
96+
97+
enum Color(val rgb: Int):
98+
case Red extends Color(0xFF0000) with EnumValue
99+
case Green extends Color(0x00FF00) with Lime
100+
case Blue extends Color(0x0000FF)
101+
102+
object prefixes:
103+
class C:
104+
object N:
105+
type U
106+
object Test:
107+
val c: C = ???
108+
def k2: c.N.U = ???
109+
import c.N.*
110+
def k3: U = ??? // TypeTree if not a select
111+
object Alt:
112+
val c: C = ???
113+
import c.N
114+
def k4: N.U = ???
115+
end prefixes

0 commit comments

Comments
 (0)