From e258c87ea3cdf716d23d8677ab670927f5b671e3 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Mon, 17 Nov 2025 11:10:39 -0800 Subject: [PATCH] CheckUnused examines type of Apply --- .../tools/dotc/transform/CheckUnused.scala | 3 ++- tests/warn/i24457.scala | 14 ++++++++++++++ tests/warn/i24459.scala | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/warn/i24457.scala create mode 100644 tests/warn/i24459.scala diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index 26a20a1bf176..745c94d0e904 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -122,7 +122,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha case Apply(Select(left, nme.Equals | nme.NotEquals), right :: Nil) => val caneq = defn.CanEqualClass.typeRef.appliedTo(left.tpe.widen :: right.tpe.widen :: Nil) resolveScoped(caneq) - case _ => + case tree => + refUsage(tree.tpe.typeSymbol) tree override def transformTypeApply(tree: TypeApply)(using Context): tree.type = diff --git a/tests/warn/i24457.scala b/tests/warn/i24457.scala new file mode 100644 index 000000000000..76b7df8ed9c9 --- /dev/null +++ b/tests/warn/i24457.scala @@ -0,0 +1,14 @@ +//> using options -Werror -Wunused:all +///> using scala 3.8.0-RC1 + +object test { + private case class Impl() + inline def makeImpl(): Any = Impl() // inline is not germane + + def seth = + case class Loop() + println(Loop()) +} + +@main def main = println: + test.makeImpl() diff --git a/tests/warn/i24459.scala b/tests/warn/i24459.scala new file mode 100644 index 000000000000..06aba7348398 --- /dev/null +++ b/tests/warn/i24459.scala @@ -0,0 +1,17 @@ +//> using options -Werror -Wunused:all +///> using scala 3.8.0-RC1 + +trait Suite { + inline def test(body: => Any): Any = body +} + +object Test { + private case class I() +} + +class Test extends Suite { + test { + val i = Test.I() + i.hashCode + } +}