From 067e096bf9dacea5742ddad3324b22db51923e3b Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 15 Oct 2025 10:36:35 -0700 Subject: [PATCH 1/2] Ignore compiletime.testing for now Import of compiletime.testing nullifies unused lint --- .../tools/dotc/transform/CheckUnused.scala | 5 +++ tests/warn/i21805.scala | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/warn/i21805.scala diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index 11a4f33cb9ba..2e870f447893 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -433,6 +433,7 @@ object CheckUnused: if inliners == 0 && languageImport(imp.expr).isEmpty && !imp.isGeneratedByEnum + && !imp.isCompiletimeTesting && !ctx.owner.name.isReplWrapperName then imps.put(imp, ()) @@ -990,6 +991,10 @@ object CheckUnused: then imp.expr.tpe.allMembers.exists(_.symbol.isCanEqual) else imp.expr.tpe.member(sel.name.toTermName).hasAltWith(_.symbol.isCanEqual) + /** No mechanism for detection yet. */ + def isCompiletimeTesting: Boolean = + imp.expr.symbol == defn.CompiletimeTestingPackage//.moduleClass + extension (pos: SrcPos) def isZeroExtentSynthetic: Boolean = pos.span.isSynthetic && pos.span.isZeroExtent def isSynthetic: Boolean = pos.span.isSynthetic && pos.span.exists diff --git a/tests/warn/i21805.scala b/tests/warn/i21805.scala new file mode 100644 index 000000000000..4fdcae85910d --- /dev/null +++ b/tests/warn/i21805.scala @@ -0,0 +1,31 @@ +//> using options -Wunused:imports + +def i23967: Boolean = { + //import scala.compiletime.testing.typeCheckErrors + import scala.compiletime.testing.* // nowarn + typeChecks("2 + 2") +} + +package p: + val code = """"hello, world"""" +package c: + class C(i: Int) + +package q: + import c.* // warn should be nowarn + import p.* // warn should be nowarn + import scala.compiletime.testing.* + def test() = typeCheckErrors("""println(C("hello, world"))""") + def ok() = typeChecks("println(code)") + inline def f(inline i: Int) = 42 + i + +package i23967b: + package ok: + import scala.compiletime.testing.* // nowarn + def test() = typeChecks("42 + 27") + package nok: + import scala.compiletime.testing.typeChecks // nowarn + def test() = typeChecks("42 + 27") + +@main def Test = println: + q.f(27) From 18f1a570a0e9c9b2220da238183ca4f422d63bc7 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 22 Oct 2025 14:42:47 +0200 Subject: [PATCH 2/2] Import of compiletime.testing nullifies unused lint [Cherry-picked b3256812e6da4cba643a2685ce606ded40374acf][modified]