From 3e792864055d720ec21a208e36a039fcd80f6712 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 1 Feb 2025 17:08:59 -0800 Subject: [PATCH 1/2] Status quo --- tests/warn/i21805.scala | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/warn/i21805.scala diff --git a/tests/warn/i21805.scala b/tests/warn/i21805.scala new file mode 100644 index 000000000000..f53b899c0176 --- /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.* // warn + 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.* // warn + def test() = typeChecks("42 + 27") + package nok: + import scala.compiletime.testing.typeChecks // warn + def test() = typeChecks("42 + 27") + +@main def Test = println: + q.f(27) From 2ac247ed32f3bcf6d6db79607069132616464817 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Mon, 22 Sep 2025 20:22:52 -0700 Subject: [PATCH 2/2] Ignore compiletime.testing for now --- compiler/src/dotty/tools/dotc/transform/CheckUnused.scala | 5 +++++ tests/warn/i21805.scala | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index 1c6bae6b112a..913a2ad1829d 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -500,6 +500,7 @@ object CheckUnused: if inliners == 0 && languageImport(imp.expr).isEmpty && !imp.isGeneratedByEnum + && !imp.isCompiletimeTesting && !ctx.owner.name.isReplWrapperName then imps.put(imp, ()) @@ -1031,6 +1032,10 @@ object CheckUnused: def isGeneratedByEnum: Boolean = imp.symbol.exists && imp.symbol.owner.is(Enum, butNot = Case) + /** 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 index f53b899c0176..4fdcae85910d 100644 --- a/tests/warn/i21805.scala +++ b/tests/warn/i21805.scala @@ -2,7 +2,7 @@ def i23967: Boolean = { //import scala.compiletime.testing.typeCheckErrors - import scala.compiletime.testing.* // warn + import scala.compiletime.testing.* // nowarn typeChecks("2 + 2") } @@ -21,10 +21,10 @@ package q: package i23967b: package ok: - import scala.compiletime.testing.* // warn + import scala.compiletime.testing.* // nowarn def test() = typeChecks("42 + 27") package nok: - import scala.compiletime.testing.typeChecks // warn + import scala.compiletime.testing.typeChecks // nowarn def test() = typeChecks("42 + 27") @main def Test = println: