Skip to content

Commit b325681

Browse files
committed
Import of compiletime.testing nullifies unused lint
1 parent 4d28ffd commit b325681

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,12 @@ object CheckUnused:
501501
if inliners == 0
502502
&& languageImport(imp.expr).isEmpty
503503
&& !imp.isGeneratedByEnum
504-
&& !imp.isCompiletimeTesting
505504
&& !ctx.owner.name.isReplWrapperName
506505
then
507-
imps.put(imp, ())
506+
if imp.isCompiletimeTesting then
507+
isNullified = true
508+
else
509+
imps.put(imp, ())
508510
case tree: Bind =>
509511
if !tree.name.isInstanceOf[DerivedName] && !tree.name.is(WildcardParamName) then
510512
if tree.hasAttachment(NoWarn) then
@@ -534,6 +536,9 @@ object CheckUnused:
534536
asss.addOne(sym)
535537
else
536538
refs.addOne(sym)
539+
540+
// currently compiletime.testing is completely erased, so ignore the unit
541+
var isNullified = false
537542
end RefInfos
538543

539544
// Names are resolved by definitions and imports, which have four precedence levels:
@@ -548,7 +553,7 @@ object CheckUnused:
548553
inline def weakerThan(q: Precedence): Boolean = p > q
549554
inline def isNone: Boolean = p == NoPrecedence
550555

551-
def reportUnused()(using Context): Unit =
556+
def reportUnused()(using Context): Unit = if !refInfos.isNullified then
552557
for (msg, pos, origin) <- warnings do
553558
if origin.isEmpty then report.warning(msg, pos)
554559
else report.warning(msg, pos, origin)

tests/warn/i21805.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Wunused:imports
1+
//> using options -Wunused:all
22

33
def i23967: Boolean = {
44
//import scala.compiletime.testing.typeCheckErrors
@@ -12,8 +12,8 @@ package c:
1212
class C(i: Int)
1313

1414
package q:
15-
import c.* // warn should be nowarn
16-
import p.* // warn should be nowarn
15+
import c.* // nowarn, unit is nullified
16+
import p.* // nowarn
1717
import scala.compiletime.testing.*
1818
def test() = typeCheckErrors("""println(C("hello, world"))""")
1919
def ok() = typeChecks("println(code)")

0 commit comments

Comments
 (0)