Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
&& tree.qualifier.tpe.match
case ThisType(_) | SuperType(_, _) => false
case qualtpe => qualtpe.isStable
if tree.srcPos.isSynthetic && tree.symbol == defn.TypeTest_unapply then
val sym = tree.symbol
.orElse:
tree.typeOpt.resultType.typeSymbol
if tree.srcPos.isSynthetic && sym == defn.TypeTest_unapply then
tree.qualifier.tpe.underlying.finalResultType match
case AppliedType(tycon, args) =>
val res =
Expand All @@ -92,11 +95,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
val target = res.dealias.typeSymbol
resolveUsage(target, target.name, res.importPrefix.skipPackageObject) // case _: T =>
case _ =>
else if isImportable || name.exists(_ != tree.symbol.name) then
else if isImportable || name.exists(_ != sym.name) then
if !ignoreTree(tree) then
resolveUsage(tree.symbol, name, tree.qualifier.tpe)
resolveUsage(sym, name, tree.qualifier.tpe)
else if !ignoreTree(tree) then
refUsage(tree.symbol)
refUsage(sym)
refInfos.isAssignment = false
tree

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

override def transformTypeApply(tree: TypeApply)(using Context): tree.type =
if tree.symbol.exists && tree.symbol.isConstructor then
refUsage(tree.symbol.owner) // redundant with use of resultType in transformSelect of fun
tree

override def prepareForAssign(tree: Assign)(using Context): Context =
tree.lhs.putAttachment(AssignmentTarget, ()) // don't take LHS reference as a read
ctx
Expand Down
27 changes: 27 additions & 0 deletions tests/warn/i23694.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//> using options -Wunused:privates

trait A:
def get: Any = new A.C // select has type [T] =>> C[T]
def cc: Any = new A.CC // select has type CC

object A:
private class C[T]
private type CC[T] = C[T]

trait B:
def get: Any = new B.C

object B:
private class C

// duplicate issue #23960
package net.marek.tyre.automaton:

private[tyre] class TyreCompiler[IN <: Tuple, R]:
private def compile[IS <: Tuple, T](xs: List[T]): String = xs match // warn
case _: List[t] =>
Loop[IS, t](null.asInstanceOf[t]).build
private class Loop[IS <: Tuple, T](
val i: T,
):
def build = "27"
Loading