Skip to content

Commit 9143889

Browse files
committed
address review comments
1 parent 1572968 commit 9143889

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,10 +1873,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
18731873
var alreadyStripped = false
18741874
cases.mapconserve { cas =>
18751875
val case1 = typedCase(cas, sel, wideSelType, pt)(using caseCtx)
1876+
caseCtx = Nullables.afterPatternContext(sel, case1.pat)
18761877
if !alreadyStripped && Nullables.matchesNull(case1) then
18771878
wideSelType = wideSelType.stripNull
18781879
alreadyStripped = true
1879-
caseCtx = Nullables.afterPatternContext(sel, case1.pat)
18801880
case1
18811881
}
18821882

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Test flow-typing when NotNullInfos are from cases
2+
3+
object MatchTest {
4+
def f6(s: String | Null): String = s match {
5+
case s2 => s2 // error
6+
case null => "other" // error
7+
case s3 => s3
8+
}
9+
10+
def f7(s: String | Null): String = s match {
11+
case null => "other"
12+
case null => "other" // error
13+
case s3 => s3
14+
}
15+
}

tests/explicit-nulls/pos/flow-match.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ object MatchTest {
4444
case s2 => s2
4545
case s3 => s3
4646
}
47+
48+
def f6(s: String | Null): String = s match {
49+
case s3: String => s3
50+
case null => "other"
51+
case s4 => s4
52+
}
53+
54+
def f7(s: String | Null): String = s match {
55+
case s2 => s2.nn
56+
case s3 => s3
57+
}
4758
}

0 commit comments

Comments
 (0)