Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisL2 committed Nov 4, 2024
1 parent 855c7c9 commit ce53f6e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 42 deletions.
14 changes: 9 additions & 5 deletions tests/explicit-nulls/warn/i21577.check
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
-- [E121] Pattern Match Warning: tests/explicit-nulls/warn/i21577.scala:5:9 --------------------------------------------
5 | case _ => // warn
5 | case _ => // warn: null only
| ^
| Unreachable case except for null (if this is intentional, consider writing case null => instead).
-- [E121] Pattern Match Warning: tests/explicit-nulls/warn/i21577.scala:12:9 -------------------------------------------
12 | case _ => // warn
12 | case _ => // warn: null only
| ^
| Unreachable case except for null (if this is intentional, consider writing case null => instead).
-- [E121] Pattern Match Warning: tests/explicit-nulls/warn/i21577.scala:16:7 -------------------------------------------
16 | case _ => // warn: null only
| ^
| Unreachable case except for null (if this is intentional, consider writing case null => instead).
-- [E030] Match case Unreachable Warning: tests/explicit-nulls/warn/i21577.scala:20:7 ----------------------------------
20 | case _ => // warn
20 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E029] Pattern Match Exhaustivity Warning: tests/explicit-nulls/warn/i21577.scala:29:27 -----------------------------
29 |def f7(s: String | Null) = s match // warn
29 |def f7(s: String | Null) = s match // warn: not exhuastive
| ^
| match may not be exhaustive.
|
| It would fail on pattern case: _: Null
|
| longer explanation available when compiling with `-explain`
-- [E029] Pattern Match Exhaustivity Warning: tests/explicit-nulls/warn/i21577.scala:36:33 -----------------------------
36 |def f9(s: String | Int | Null) = s match // warn
36 |def f9(s: String | Int | Null) = s match // warn: not exhuastive
| ^
| match may not be exhaustive.
|
Expand Down
12 changes: 6 additions & 6 deletions tests/explicit-nulls/warn/i21577.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ def f(s: String) =
val s2 = s.trim()
s2 match
case s3: String =>
case _ => // warn
case _ => // warn: null only


def f2(s: String | Null) =
val s2 = s.nn.trim()
s2 match
case s3: String =>
case _ => // warn
case _ => // warn: null only

def f3(s: String | Null) = s match
case s2: String =>
case _ =>
case _ => // warn: null only

def f5(s: String) = s match
case _: String =>
case _ => // warn
case _ => // warn: unreachable

def f6(s: String) = s.trim() match
case _: String =>
Expand All @@ -26,13 +26,13 @@ def f6(s: String) = s.trim() match
def f61(s: String) = s.trim() match
case _: String =>

def f7(s: String | Null) = s match // warn
def f7(s: String | Null) = s match // warn: not exhuastive
case _: String =>

def f8(s: String | Null) = s match
case _: String =>
case null =>

def f9(s: String | Int | Null) = s match // warn
def f9(s: String | Int | Null) = s match // warn: not exhuastive
case _: String =>
case null =>
4 changes: 2 additions & 2 deletions tests/warn/i20121.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ case class CC_B[A](a: A) extends T_A[A, X]

val v_a: T_A[X, X] = CC_B(null)
val v_b = v_a match
case CC_B(_) => 0 // warn: unreachable
case _ => 1
case CC_B(_) => 0
case _ => 1 // warn: null only
// for CC_B[A] to match T_A[X, X]
// A := X
// so require X, aka T_A[Byte, Byte]
Expand Down
2 changes: 1 addition & 1 deletion tests/warn/i20122.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ case class CC_E(a: CC_C[Char, Byte])

val v_a: T_B[Int, CC_A] = CC_B(CC_E(CC_C(null)))
val v_b = v_a match
case CC_B(CC_E(CC_C(_))) => 0 // warn: unreachable
case CC_B(CC_E(CC_C(_))) => 0
case _ => 1
// for CC_B[A, C] to match T_B[C, CC_A]
// C <: Int, ok
Expand Down
2 changes: 1 addition & 1 deletion tests/warn/i20123.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ case class CC_G[A, C](c: C) extends T_A[A, C]
val v_a: T_A[Boolean, T_B[Boolean]] = CC_G(null)
val v_b = v_a match {
case CC_D() => 0
case CC_G(_) => 1 // warn: unreachable
case CC_G(_) => 1
// for CC_G[A, C] to match T_A[Boolean, T_B[Boolean]]
// A := Boolean, which is ok
// C := T_B[Boolean],
Expand Down
30 changes: 17 additions & 13 deletions tests/warn/redundant-null.check
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:10:7 -----------------------------------------
10 | case _: n.type => // warn
10 | case _: n.type => // warn: unreachable
| ^^^^^^^^^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:12:7 -----------------------------------------
12 | case _ => // warn
12 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:13:7 -----------------------------------------
13 | case _ => // warn
13 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:18:7 -----------------------------------------
18 | case _ => 3 // warn
18 | case _ => 3 // warn: unreachable
| ^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:23:7 -----------------------------------------
23 | case _: B => // warn
23 | case _: B => // warn: unreachable
| ^^^^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:24:7 -----------------------------------------
24 | case _ => // warn
24 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:25:7 -----------------------------------------
25 | case null => // warn
25 | case null => // warn: unreachable
| ^^^^
| Unreachable case
-- [E121] Pattern Match Warning: tests/warn/redundant-null.scala:30:7 --------------------------------------------------
30 | case _ => // warn
30 | case _ => // warn: null only
| ^
| Unreachable case except for null (if this is intentional, consider writing case null => instead).
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:31:7 -----------------------------------------
31 | case null => // warn
31 | case null => // warn: unreachable
| ^^^^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:32:7 -----------------------------------------
32 | case _ => // warn
32 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:33:7 -----------------------------------------
33 | case _ => // warn
33 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:37:7 -----------------------------------------
37 | case _ => println("unreachable") // warn
37 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:41:7 -----------------------------------------
41 | case _ => // warn
41 | case _ => // warn: unreachable
| ^
| Unreachable case
-- [E121] Pattern Match Warning: tests/warn/redundant-null.scala:45:7 --------------------------------------------------
45 | case _ => // warn: null only
| ^
| Unreachable case except for null (if this is intentional, consider writing case null => instead).
32 changes: 18 additions & 14 deletions tests/warn/redundant-null.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@ val n = null
def f(s: A) = s match
case _: n.type =>
case _: A =>
case _: n.type => // warn
case _: n.type => // warn: unreachable
case null =>
case _ => // warn
case _ => // warn
case _ => // warn: unreachable
case _ => // warn: unreachable

def f2(s: A | B | C) = s match
case _: A => 0
case _: C | null | _: B => 1
case _ => 3 // warn
case _ => 3 // warn: unreachable

def f3(s: A | B) = s match
case _: A =>
case _ =>
case _: B => // warn
case _ => // warn
case null => // warn
case _: B => // warn: unreachable
case _ => // warn: unreachable
case null => // warn: unreachable

def f4(s: String | Int) = s match
case _: Int =>
case _: String =>
case _ => // warn
case null => // warn
case _ => // warn
case _ => // warn
case _ => // warn: null only
case null => // warn: unreachable
case _ => // warn: unreachable
case _ => // warn: unreachable

def f5(x: String) = x match
case x => println("catch all")
case _ => println("unreachable") // warn
case x =>
case _ => // warn: unreachable

def test(s: String | Null) = s match
case ss =>
case _ => // warn
case _ => // warn: unreachable

def test2(s: String | Null) = s match
case ss: String =>
case _ => // warn: null only

0 comments on commit ce53f6e

Please sign in to comment.