Skip to content

Commit

Permalink
Drop showAlways on UncheckedTypePattern
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 11, 2023
1 parent 34cd237 commit 2238ceb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 25 deletions.
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,6 @@ extends Message(PatternMatchExhaustivityID) {

class UncheckedTypePattern(argType: Type, whyNot: String)(using Context)
extends PatternMatchMsg(UncheckedTypePatternID) {
override def showAlways = true
def msg(using Context) = i"the type test for $argType cannot be checked at runtime because $whyNot"
def explain(using Context) =
i"""|Type arguments and type refinements are erased during compile time, thus it's
Expand Down
8 changes: 1 addition & 7 deletions tests/warn/enum-approx2.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- [E030] Match case Unreachable Warning: tests/warn/enum-approx2.scala:7:12 -------------------------------------------
7 | case Fun(x: Exp[Int => String]) => ??? // warn: unreachable // warn: unchecked
7 | case Fun(x: Exp[Int => String]) => ??? // warn: unreachable // also: unchecked (hidden)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| Unreachable case
-- [E121] Pattern Match Warning: tests/warn/enum-approx2.scala:8:9 -----------------------------------------------------
Expand All @@ -12,9 +12,3 @@
|the type test for Fun[Int, Double] cannot be checked at runtime because its type arguments can't be determined from Exp[Int => Int]
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/enum-approx2.scala:7:13 ------------------------------------------
7 | case Fun(x: Exp[Int => String]) => ??? // warn: unreachable // warn: unchecked
| ^
|the type test for Exp[Int => String] cannot be checked at runtime because its type arguments can't be determined from Exp[Int => Int]
|
| longer explanation available when compiling with `-explain`
2 changes: 1 addition & 1 deletion tests/warn/enum-approx2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ case class Fun[A, B](f: Exp[A => B]) extends Exp[A => B]
class Test {
def eval(e: Fun[Int, Int]) = e match {
case Fun(x: Fun[Int, Double]) => ??? // warn: unchecked
case Fun(x: Exp[Int => String]) => ??? // warn: unreachable // warn: unchecked
case Fun(x: Exp[Int => String]) => ??? // warn: unreachable // also: unchecked (hidden)
case _ => // warn: unreachable-only-null
}
}
16 changes: 2 additions & 14 deletions tests/warn/i16451.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- [E030] Match case Unreachable Warning: tests/warn/i16451.scala:14:9 -------------------------------------------------
14 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // warn: unchecked
14 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/i16451.scala:22:9 -------------------------------------------------
22 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // warn: unchecked
22 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Unreachable case
-- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:13:9 ------------------------------------------------
Expand All @@ -12,24 +12,12 @@
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:14:9 ------------------------------------------------
14 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // warn: unchecked
| ^
|the type test for Wrapper[(Color.Green : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color]
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:21:9 ------------------------------------------------
21 | case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
| ^
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Any
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:22:9 ------------------------------------------------
22 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // warn: unchecked
| ^
|the type test for Wrapper[(Color.Green : Color)] cannot be checked at runtime because its type arguments can't be determined from Any
|
| longer explanation available when compiling with `-explain`
-- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:25:9 ------------------------------------------------
25 | case x: Wrapper[Color.Red.type] => Some(x) // error: unreachable // error: unchecked
| ^
Expand Down
4 changes: 2 additions & 2 deletions tests/warn/i16451.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ case class Wrapper[A](value: A)
object Test:
def test_correct(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
case x: Wrapper[Color.Green.type] => None // warn: unreachable // warn: unchecked
case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)

def test_different(x: Wrapper[Color]): Option[Wrapper[Color]] = x match
case x @ Wrapper(_: Color.Red.type) => Some(x)
case x @ Wrapper(_: Color.Green.type) => None

def test_any(x: Any): Option[Wrapper[Color.Red.type]] = x match
case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked
case x: Wrapper[Color.Green.type] => None // warn: unreachable // warn: unchecked
case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden)

def test_wrong(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match
case x: Wrapper[Color.Red.type] => Some(x) // error: unreachable // error: unchecked
Expand Down

0 comments on commit 2238ceb

Please sign in to comment.