Skip to content

Commit ee6d386

Browse files
committed
Reuse & switch to UncheckedTypePattern
1 parent 10c83bd commit ee6d386

File tree

7 files changed

+39
-15
lines changed

7 files changed

+39
-15
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,9 @@ extends Message(PatternMatchExhaustivityID) {
895895
}
896896
}
897897

898-
class UncheckedTypePattern(msgFn: => String)(using Context)
898+
class UncheckedTypePattern(argType: Type, whyNot: String)(using Context)
899899
extends PatternMatchMsg(UncheckedTypePatternID) {
900-
def msg(using Context) = msgFn
900+
def msg(using Context) = i"the type test for $argType cannot be checked at runtime because $whyNot"
901901
def explain(using Context) =
902902
i"""|Type arguments and type refinements are erased during compile time, thus it's
903903
|impossible to check them at run-time.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ object TypeTestsCasts {
363363
if !isTrusted && !isUnchecked then
364364
val whyNot = whyUncheckable(expr.tpe, argType, tree.span)
365365
if whyNot.nonEmpty then
366-
report.uncheckedWarning(em"the type test for $argType cannot be checked at runtime because $whyNot", expr.srcPos)
366+
report.uncheckedWarning(UncheckedTypePattern(argType, whyNot), expr.srcPos)
367367
transformTypeTest(expr, argType,
368368
flagUnrelated = enclosingInlineds.isEmpty) // if test comes from inlined code, dont't flag it even if it always false
369369
}

tests/neg/15981.check

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
-- Error: tests/neg/15981.scala:4:45 -----------------------------------------------------------------------------------
1+
-- [E092] Pattern Match Error: tests/neg/15981.scala:4:45 --------------------------------------------------------------
22
4 | override def equals(any: Any): Boolean = any.isInstanceOf[PosInt] // error
33
| ^^^
44
| the type test for PosInt cannot be checked at runtime because it's a local class
5+
|
6+
| longer explanation available when compiling with `-explain`

tests/neg/i12253.check

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
-- Error: tests/neg/i12253.scala:13:10 ---------------------------------------------------------------------------------
1+
-- [E092] Pattern Match Error: tests/neg/i12253.scala:13:10 ------------------------------------------------------------
22
13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error
33
| ^
44
|the type test for extractors.q2.reflect.Term cannot be checked at runtime because it refers to an abstract type member or type parameter
5-
-- Error: tests/neg/i12253.scala:13:38 ---------------------------------------------------------------------------------
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E092] Pattern Match Error: tests/neg/i12253.scala:13:38 ------------------------------------------------------------
68
13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error
79
| ^
810
|the type test for q1.reflect.Select cannot be checked at runtime because it refers to an abstract type member or type parameter
11+
|
12+
| longer explanation available when compiling with `-explain`
913
there was 1 deprecation warning; re-run with -deprecation for details

tests/neg/i16728.check

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
-- Error: tests/neg/i16728.scala:18:11 ---------------------------------------------------------------------------------
1+
-- [E092] Pattern Match Error: tests/neg/i16728.scala:18:11 ------------------------------------------------------------
22
18 | case tx : C[Int]#X => // error
33
| ^
44
| the type test for C[Int] cannot be checked at runtime because its type arguments can't be determined from A
5+
|
6+
| longer explanation available when compiling with `-explain`

tests/neg/i4812.check

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1-
-- Error: tests/neg/i4812.scala:8:11 -----------------------------------------------------------------------------------
1+
-- [E092] Pattern Match Error: tests/neg/i4812.scala:8:11 --------------------------------------------------------------
22
8 | case prev: A => // error: the type test for A cannot be checked at runtime
33
| ^
44
| the type test for A cannot be checked at runtime because it's a local class
5-
-- Error: tests/neg/i4812.scala:18:11 ----------------------------------------------------------------------------------
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E092] Pattern Match Error: tests/neg/i4812.scala:18:11 -------------------------------------------------------------
68
18 | case prev: A => // error: the type test for A cannot be checked at runtime
79
| ^
810
| the type test for A cannot be checked at runtime because it's a local class
9-
-- Error: tests/neg/i4812.scala:28:11 ----------------------------------------------------------------------------------
11+
|
12+
| longer explanation available when compiling with `-explain`
13+
-- [E092] Pattern Match Error: tests/neg/i4812.scala:28:11 -------------------------------------------------------------
1014
28 | case prev: A => // error: the type test for A cannot be checked at runtime
1115
| ^
1216
| the type test for A cannot be checked at runtime because it's a local class
13-
-- Error: tests/neg/i4812.scala:38:11 ----------------------------------------------------------------------------------
17+
|
18+
| longer explanation available when compiling with `-explain`
19+
-- [E092] Pattern Match Error: tests/neg/i4812.scala:38:11 -------------------------------------------------------------
1420
38 | case prev: A => // error: the type test for A cannot be checked at runtime
1521
| ^
1622
| the type test for A cannot be checked at runtime because it's a local class
17-
-- Error: tests/neg/i4812.scala:50:13 ----------------------------------------------------------------------------------
23+
|
24+
| longer explanation available when compiling with `-explain`
25+
-- [E092] Pattern Match Error: tests/neg/i4812.scala:50:13 -------------------------------------------------------------
1826
50 | case prev: A => // error: the type test for A cannot be checked at runtime
1927
| ^
2028
| the type test for A cannot be checked at runtime because it's a local class
21-
-- Error: tests/neg/i4812.scala:60:11 ----------------------------------------------------------------------------------
29+
|
30+
| longer explanation available when compiling with `-explain`
31+
-- [E092] Pattern Match Error: tests/neg/i4812.scala:60:11 -------------------------------------------------------------
2232
60 | case prev: A => // error: the type test for A cannot be checked at runtime
2333
| ^
2434
| the type test for A cannot be checked at runtime because it's a local class
25-
-- Error: tests/neg/i4812.scala:96:11 ----------------------------------------------------------------------------------
35+
|
36+
| longer explanation available when compiling with `-explain`
37+
-- [E092] Pattern Match Error: tests/neg/i4812.scala:96:11 -------------------------------------------------------------
2638
96 | case x: B => // error: the type test for B cannot be checked at runtime
2739
| ^
2840
| the type test for B cannot be checked at runtime because it's a local class
41+
|
42+
| longer explanation available when compiling with `-explain`

tests/neg/nowarn.check

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ Matching filters for @nowarn or -Wconf:
6666
49 |def t7c = f // warning (deprecation)
6767
| ^
6868
| method f is deprecated
69-
-- Unchecked Warning: tests/neg/nowarn.scala:55:7 ----------------------------------------------------------------------
69+
-- [E092] Pattern Match Unchecked Warning: tests/neg/nowarn.scala:55:7 -------------------------------------------------
7070
55 | case _: List[Int] => 0 // warning (patmat, unchecked)
7171
| ^
7272
|the type test for List[Int] cannot be checked at runtime because its type arguments can't be determined from Any
73+
|
74+
| longer explanation available when compiling with `-explain`
7375
-- Error: tests/neg/nowarn.scala:33:1 ----------------------------------------------------------------------------------
7476
33 |@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
7577
|^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)