Skip to content

Commit c48a60d

Browse files
committed
Drill through type lambda for tree symbol
1 parent 5bba231 commit c48a60d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.tpd.*
55
import dotty.tools.dotc.ast.untpd, untpd.ImportSelector
66
import dotty.tools.dotc.config.ScalaSettings
77
import dotty.tools.dotc.core.Contexts.*
8+
import dotty.tools.dotc.core.Decorators.*
89
import dotty.tools.dotc.core.Flags.*
910
import dotty.tools.dotc.core.Names.{Name, SimpleName, DerivedName, TermName, termName}
1011
import dotty.tools.dotc.core.NameOps.{isAnonymousFunctionName, isReplWrapperName, setterName}
@@ -80,7 +81,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
8081
&& tree.qualifier.tpe.match
8182
case ThisType(_) | SuperType(_, _) => false
8283
case qualtpe => qualtpe.isStable
83-
if tree.srcPos.isSynthetic && tree.symbol == defn.TypeTest_unapply then
84+
val sym = tree.symbol.orElse(tree.typeOpt.resultType.typeSymbol)
85+
if tree.srcPos.isSynthetic && sym == defn.TypeTest_unapply then
8486
tree.qualifier.tpe.underlying.finalResultType match
8587
case AppliedType(tycon, args) =>
8688
val res =
@@ -90,11 +92,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
9092
val target = res.dealias.typeSymbol
9193
resolveUsage(target, target.name, res.importPrefix.skipPackageObject) // case _: T =>
9294
case _ =>
93-
else if isImportable || name.exists(_ != tree.symbol.name) then
95+
else if isImportable || name.exists(_ != sym.name) then
9496
if !ignoreTree(tree) then
95-
resolveUsage(tree.symbol, name, tree.qualifier.tpe)
97+
resolveUsage(sym, name, tree.qualifier.tpe)
9698
else if !ignoreTree(tree) then
97-
refUsage(tree.symbol)
99+
refUsage(sym)
98100
refInfos.isAssignment = false
99101
tree
100102

tests/warn/i23694.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -Wunused:privates
2+
3+
trait A:
4+
def get: Any = new A.C
5+
6+
object A:
7+
private class C[T]
8+
9+
trait B:
10+
def get: Any = new B.C
11+
12+
object B:
13+
private class C

0 commit comments

Comments
 (0)