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 {
921921 else Empty
922922 }.reduce((a, b) => Or (List (a, b)))
923923
924+ def isNull (tree : Tree ): Boolean = tree match {
925+ case Literal (Constant (null )) => true
926+ case _ => false
927+ }
928+
924929 (1 until cases.length).foreach { i =>
925930 val prevs = projectPrevCases(cases.take(i))
926931
@@ -944,7 +949,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
944949 }
945950
946951 // 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) ) {
948953 simplify(minus(covered, prevs)) match {
949954 case Typ (ConstantType (Constant (null )), _) =>
950955 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