Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f49571b

Browse files
Drill through type lambda for tree symbol
Select node in `new p.C[T]` has a lambda type, so the symbol `C` is found in its result type. The TypeApply has a symbol which is the constructor of C. Both trees are used to register `C` as used.
1 parent dfacd3f commit f49571b

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
8282
&& tree.qualifier.tpe.match
8383
case ThisType(_) | SuperType(_, _) => false
8484
case qualtpe => qualtpe.isStable
85-
if tree.srcPos.isSynthetic && tree.symbol == defn.TypeTest_unapply then
85+
val sym = tree.symbol
86+
.orElse:
87+
tree.typeOpt.resultType.typeSymbol
88+
if tree.srcPos.isSynthetic && sym == defn.TypeTest_unapply then
8689
tree.qualifier.tpe.underlying.finalResultType match
8790
case AppliedType(tycon, args) =>
8891
val res =
@@ -92,11 +95,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
9295
val target = res.dealias.typeSymbol
9396
resolveUsage(target, target.name, res.importPrefix.skipPackageObject) // case _: T =>
9497
case _ =>
95-
else if isImportable || name.exists(_ != tree.symbol.name) then
98+
else if isImportable || name.exists(_ != sym.name) then
9699
if !ignoreTree(tree) then
97-
resolveUsage(tree.symbol, name, tree.qualifier.tpe)
100+
resolveUsage(sym, name, tree.qualifier.tpe)
98101
else if !ignoreTree(tree) then
99-
refUsage(tree.symbol)
102+
refUsage(sym)
100103
refInfos.isAssignment = false
101104
tree
102105

@@ -126,6 +129,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
126129
case _ =>
127130
tree
128131

132+
override def transformTypeApply(tree: TypeApply)(using Context): tree.type =
133+
if tree.symbol.exists && tree.symbol.isConstructor then
134+
refUsage(tree.symbol.owner) // redundant with use of resultType in transformSelect of fun
135+
tree
136+
129137
override def prepareForAssign(tree: Assign)(using Context): Context =
130138
tree.lhs.putAttachment(AssignmentTarget, ()) // don't take LHS reference as a read
131139
ctx

‎tests/warn/i23694.scala‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//> using options -Wunused:privates
2+
3+
trait A:
4+
def get: Any = new A.C // select has type [T] =>> C[T]
5+
def cc: Any = new A.CC // select has type CC
6+
7+
object A:
8+
private class C[T]
9+
private type CC[T] = C[T]
10+
11+
trait B:
12+
def get: Any = new B.C
13+
14+
object B:
15+
private class C
16+
17+
// duplicate issue #23960
18+
package net.marek.tyre.automaton:
19+
20+
private[tyre] class TyreCompiler[IN <: Tuple, R]:
21+
private def compile[IS <: Tuple, T](xs: List[T]): String = xs match // warn
22+
case _: List[t] =>
23+
Loop[IS, t](null.asInstanceOf[t]).build
24+
private class Loop[IS <: Tuple, T](
25+
val i: T,
26+
):
27+
def build = "27"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /