Skip to content

Commit 041ad13

Browse files
Backport "Ignore warnings when compiletime.testing is imported" to 3.7.4 (#24229)
Backports #24036 to the 3.7.4. PR submitted by the release tooling.
2 parents 6a206ab + 18f1a57 commit 041ad13

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ object CheckUnused:
433433
if inliners == 0
434434
&& languageImport(imp.expr).isEmpty
435435
&& !imp.isGeneratedByEnum
436+
&& !imp.isCompiletimeTesting
436437
&& !ctx.owner.name.isReplWrapperName
437438
then
438439
imps.put(imp, ())
@@ -990,6 +991,10 @@ object CheckUnused:
990991
then imp.expr.tpe.allMembers.exists(_.symbol.isCanEqual)
991992
else imp.expr.tpe.member(sel.name.toTermName).hasAltWith(_.symbol.isCanEqual)
992993

994+
/** No mechanism for detection yet. */
995+
def isCompiletimeTesting: Boolean =
996+
imp.expr.symbol == defn.CompiletimeTestingPackage//.moduleClass
997+
993998
extension (pos: SrcPos)
994999
def isZeroExtentSynthetic: Boolean = pos.span.isSynthetic && pos.span.isZeroExtent
9951000
def isSynthetic: Boolean = pos.span.isSynthetic && pos.span.exists

tests/warn/i21805.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//> using options -Wunused:imports
2+
3+
def i23967: Boolean = {
4+
//import scala.compiletime.testing.typeCheckErrors
5+
import scala.compiletime.testing.* // nowarn
6+
typeChecks("2 + 2")
7+
}
8+
9+
package p:
10+
val code = """"hello, world""""
11+
package c:
12+
class C(i: Int)
13+
14+
package q:
15+
import c.* // warn should be nowarn
16+
import p.* // warn should be nowarn
17+
import scala.compiletime.testing.*
18+
def test() = typeCheckErrors("""println(C("hello, world"))""")
19+
def ok() = typeChecks("println(code)")
20+
inline def f(inline i: Int) = 42 + i
21+
22+
package i23967b:
23+
package ok:
24+
import scala.compiletime.testing.* // nowarn
25+
def test() = typeChecks("42 + 27")
26+
package nok:
27+
import scala.compiletime.testing.typeChecks // nowarn
28+
def test() = typeChecks("42 + 27")
29+
30+
@main def Test = println:
31+
q.f(27)

0 commit comments

Comments
 (0)