@@ -176,6 +176,23 @@ class ClosureConstraintGenerator
176
176
void visitContinueStmt (ContinueStmt *continueStmt) { }
177
177
void visitDeferStmt (DeferStmt *deferStmt) { }
178
178
179
+ void visitThrowStmt (ThrowStmt *throwStmt) {
180
+ Type exnType =
181
+ cs.getASTContext ().getErrorDecl ()->getDeclaredInterfaceType ();
182
+ if (!exnType) {
183
+ hadError = true ;
184
+ return ;
185
+ }
186
+
187
+ SolutionApplicationTarget target (
188
+ throwStmt->getSubExpr (), closure, CTP_ThrowStmt, exnType,
189
+ /* isDiscarded=*/ false );
190
+ if (cs.generateConstraints (target, FreeTypeVariableBinding::Disallow))
191
+ hadError = true ;
192
+
193
+ cs.setSolutionApplicationTarget (throwStmt, target);
194
+ }
195
+
179
196
#define UNSUPPORTED_STMT (STMT ) void visit##STMT##Stmt(STMT##Stmt *) { \
180
197
llvm_unreachable (" Unsupported statement kind " #STMT); \
181
198
}
@@ -185,7 +202,6 @@ class ClosureConstraintGenerator
185
202
UNSUPPORTED_STMT (Case)
186
203
UNSUPPORTED_STMT (Fallthrough)
187
204
UNSUPPORTED_STMT (Fail)
188
- UNSUPPORTED_STMT (Throw)
189
205
UNSUPPORTED_STMT (PoundAssert)
190
206
#undef UNSUPPORTED_STMT
191
207
};
@@ -450,6 +466,17 @@ class ClosureConstraintApplication
450
466
return deferStmt;
451
467
}
452
468
469
+ ASTNode visitThrowStmt (ThrowStmt *throwStmt) {
470
+ // Rewrite the condition.
471
+ auto target = *solution.getConstraintSystem ()
472
+ .getSolutionApplicationTarget (throwStmt);
473
+ if (auto result = rewriteTarget (target))
474
+ throwStmt->setSubExpr (result->getAsExpr ());
475
+ else
476
+ hadError = true ;
477
+ return throwStmt;
478
+ }
479
+
453
480
#define UNSUPPORTED_STMT (STMT ) ASTNode visit##STMT##Stmt(STMT##Stmt *) { \
454
481
llvm_unreachable (" Unsupported statement kind " #STMT); \
455
482
}
@@ -459,7 +486,6 @@ class ClosureConstraintApplication
459
486
UNSUPPORTED_STMT(Case)
460
487
UNSUPPORTED_STMT(Fallthrough)
461
488
UNSUPPORTED_STMT(Fail)
462
- UNSUPPORTED_STMT(Throw)
463
489
UNSUPPORTED_STMT(PoundAssert)
464
490
#undef UNSUPPORTED_STMT
465
491
0 commit comments