File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
compiler/src/dotty/tools/dotc/transform/patmat Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -921,6 +921,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
921
921
else Empty
922
922
}.reduce((a, b) => Or (List (a, b)))
923
923
924
+ def isNull (tree : Tree ): Boolean = tree match {
925
+ case Literal (Constant (null )) => true
926
+ case _ => false
927
+ }
928
+
924
929
(1 until cases.length).foreach { i =>
925
930
val prevs = projectPrevCases(cases.take(i))
926
931
@@ -944,7 +949,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
944
949
}
945
950
946
951
// if last case is `_` and only matches `null`, produce a warning
947
- if (i == cases.length - 1 ) {
952
+ if (i == cases.length - 1 && ! isNull(pat) ) {
948
953
simplify(minus(covered, prevs)) match {
949
954
case Typ (ConstantType (Constant (null )), _) =>
950
955
ctx.warning(MatchCaseOnlyNullWarning (), pat.pos)
Original file line number Diff line number Diff line change
1
+ object Bar {
2
+ def unapply (x : String ): Some [Int ] =
3
+ Some (0 )
4
+ }
5
+
6
+ object Test {
7
+ def test (x : String ) =
8
+ x match {
9
+ case Bar (a) => a
10
+ case null => x
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments