@@ -1138,13 +1138,18 @@ class Typer extends Namer
1138
1138
1139
1139
// Overridden in InlineTyper for inline matches
1140
1140
def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(implicit ctx : Context ): Tree = {
1141
- val cases1 = harmonic(harmonize, pt)(typedCases(cases, wideSelType, pt.dropIfProto))
1141
+ val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
1142
1142
.asInstanceOf [List [CaseDef ]]
1143
1143
assignType(cpy.Match (tree)(sel, cases1), sel, cases1)
1144
1144
}
1145
1145
1146
- def typedCases (cases : List [untpd.CaseDef ], selType : Type , pt : Type )(implicit ctx : Context ): List [CaseDef ] =
1147
- cases.mapconserve(typedCase(_, selType, pt))
1146
+ def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType : Type , pt : Type )(implicit ctx : Context ): List [CaseDef ] =
1147
+ var caseCtx = ctx
1148
+ cases.mapconserve { cas =>
1149
+ val case1 = typedCase(cas, sel, wideSelType, pt)(given caseCtx )
1150
+ caseCtx = Nullables .afterPatternContext(sel, case1.pat)
1151
+ case1
1152
+ }
1148
1153
1149
1154
/** - strip all instantiated TypeVars from pattern types.
1150
1155
* run/reducable.scala is a test case that shows stripping typevars is necessary.
@@ -1171,7 +1176,7 @@ class Typer extends Namer
1171
1176
}
1172
1177
1173
1178
/** Type a case. */
1174
- def typedCase (tree : untpd.CaseDef , selType : Type , pt : Type )(implicit ctx : Context ): CaseDef = {
1179
+ def typedCase (tree : untpd.CaseDef , sel : Tree , wideSelType : Type , pt : Type )(implicit ctx : Context ): CaseDef = {
1175
1180
val originalCtx = ctx
1176
1181
val gadtCtx : Context = ctx.fresh.setFreshGADTBounds
1177
1182
@@ -1184,8 +1189,10 @@ class Typer extends Namer
1184
1189
assignType(cpy.CaseDef (tree)(pat1, guard1, body1), pat1, body1)
1185
1190
}
1186
1191
1187
- val pat1 = typedPattern(tree.pat, selType)(gadtCtx)
1188
- caseRest(pat1)(gadtCtx.fresh.setNewScope)
1192
+ val pat1 = typedPattern(tree.pat, wideSelType)(gadtCtx)
1193
+ caseRest(pat1)(
1194
+ given Nullables .caseContext(sel, pat1)(
1195
+ given gadtCtx .fresh.setNewScope))
1189
1196
}
1190
1197
1191
1198
def typedLabeled (tree : untpd.Labeled )(implicit ctx : Context ): Labeled = {
@@ -1205,7 +1212,6 @@ class Typer extends Namer
1205
1212
caseRest(ctx.fresh.setFreshGADTBounds.setNewScope)
1206
1213
}
1207
1214
1208
-
1209
1215
def typedReturn (tree : untpd.Return )(implicit ctx : Context ): Return = {
1210
1216
def returnProto (owner : Symbol , locals : Scope ): Type =
1211
1217
if (owner.isConstructor) defn.UnitType
@@ -1263,7 +1269,7 @@ class Typer extends Namer
1263
1269
def typedTry (tree : untpd.Try , pt : Type )(implicit ctx : Context ): Try = {
1264
1270
val expr2 :: cases2x = harmonic(harmonize, pt) {
1265
1271
val expr1 = typed(tree.expr, pt.dropIfProto)
1266
- val cases1 = typedCases(tree.cases, defn.ThrowableType , pt.dropIfProto)
1272
+ val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)
1267
1273
expr1 :: cases1
1268
1274
}
1269
1275
val finalizer1 = typed(tree.finalizer, defn.UnitType )
0 commit comments