@@ -422,7 +422,9 @@ class PatternMatchEmission {
422
422
void bindExprPattern (ExprPattern *pattern, ConsumableManagedValue v,
423
423
const FailureHandler &failure);
424
424
void emitGuardBranch (SILLocation loc, Expr *guard,
425
- const FailureHandler &failure);
425
+ const FailureHandler &failure,
426
+ Pattern *usingImplicitVariablesFromPattern,
427
+ CaseStmt *usingImplicitVariablesFromStmt);
426
428
427
429
void bindIrrefutablePatterns (const ClauseRow &row, ArgArray args,
428
430
bool forIrrefutableRow, bool hasMultipleItems);
@@ -1056,9 +1058,8 @@ void PatternMatchEmission::emitWildcardDispatch(ClauseMatrix &clauses,
1056
1058
1057
1059
// Emit the guard branch, if it exists.
1058
1060
if (guardExpr) {
1059
- SGF.usingImplicitVariablesForPattern (clauses[row].getCasePattern (), dyn_cast<CaseStmt>(stmt), [&]{
1060
- this ->emitGuardBranch (guardExpr, guardExpr, failure);
1061
- });
1061
+ this ->emitGuardBranch (guardExpr, guardExpr, failure,
1062
+ clauses[row].getCasePattern (), dyn_cast<CaseStmt>(stmt));
1062
1063
}
1063
1064
1064
1065
// Enter the row.
@@ -1120,7 +1121,8 @@ void PatternMatchEmission::bindExprPattern(ExprPattern *pattern,
1120
1121
bindVariable (pattern, pattern->getMatchVar (), value,
1121
1122
pattern->getType ()->getCanonicalType (),
1122
1123
/* isForSuccess*/ false , /* hasMultipleItems */ false );
1123
- emitGuardBranch (pattern, pattern->getMatchExpr (), failure);
1124
+ emitGuardBranch (pattern, pattern->getMatchExpr (), failure,
1125
+ nullptr , nullptr );
1124
1126
}
1125
1127
1126
1128
// / Bind all the irrefutable patterns in the given row, which is nothing
@@ -1229,15 +1231,26 @@ void PatternMatchEmission::bindVariable(SILLocation loc, VarDecl *var,
1229
1231
// / Evaluate a guard expression and, if it returns false, branch to
1230
1232
// / the given destination.
1231
1233
void PatternMatchEmission::emitGuardBranch (SILLocation loc, Expr *guard,
1232
- const FailureHandler &failure) {
1234
+ const FailureHandler &failure,
1235
+ Pattern *usingImplicitVariablesFromPattern,
1236
+ CaseStmt *usingImplicitVariablesFromStmt) {
1233
1237
SILBasicBlock *falseBB = SGF.B .splitBlockForFallthrough ();
1234
1238
SILBasicBlock *trueBB = SGF.B .splitBlockForFallthrough ();
1235
1239
1236
1240
// Emit the match test.
1237
1241
SILValue testBool;
1238
1242
{
1239
1243
FullExpr scope (SGF.Cleanups , CleanupLocation (guard));
1240
- testBool = SGF.emitRValueAsSingleValue (guard).getUnmanagedValue ();
1244
+ auto emitTest = [&]{
1245
+ testBool = SGF.emitRValueAsSingleValue (guard).getUnmanagedValue ();
1246
+ };
1247
+
1248
+ if (usingImplicitVariablesFromPattern)
1249
+ SGF.usingImplicitVariablesForPattern (usingImplicitVariablesFromPattern,
1250
+ usingImplicitVariablesFromStmt,
1251
+ emitTest);
1252
+ else
1253
+ emitTest ();
1241
1254
}
1242
1255
1243
1256
SGF.B .createCondBranch (loc, testBool, trueBB, falseBB);
0 commit comments