File tree 4 files changed +29
-2
lines changed
4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -3362,6 +3362,10 @@ class ConstraintSystem {
3362
3362
// / Undo the above change.
3363
3363
void removePotentialThrowSite (CatchNode catchNode);
3364
3364
3365
+ // / Retrieve the explicit caught error type for the given catch node, without
3366
+ // / attempting any inference.
3367
+ Type getExplicitCaughtErrorType (CatchNode catchNode);
3368
+
3365
3369
// / Determine the caught error type for the given catch node.
3366
3370
Type getCaughtErrorType (CatchNode node);
3367
3371
Original file line number Diff line number Diff line change @@ -969,7 +969,7 @@ class SyntacticElementConstraintGenerator
969
969
auto throwLoc = throwStmt->getThrowLoc ();
970
970
Type errorType;
971
971
if (auto catchNode = ASTScope::lookupCatchNode (module, throwLoc))
972
- errorType = catchNode. getExplicitCaughtType ( cs.getASTContext () );
972
+ errorType = cs.getExplicitCaughtErrorType (catchNode );
973
973
974
974
if (!errorType) {
975
975
if (!cs.getASTContext ().getErrorDecl ()) {
Original file line number Diff line number Diff line change @@ -511,7 +511,7 @@ void ConstraintSystem::recordPotentialThrowSite(
511
511
recordPotentialThrowSite (catchNode, site);
512
512
}
513
513
514
- Type ConstraintSystem::getCaughtErrorType (CatchNode catchNode) {
514
+ Type ConstraintSystem::getExplicitCaughtErrorType (CatchNode catchNode) {
515
515
ASTContext &ctx = getASTContext ();
516
516
517
517
// If there is an explicit caught type for this node, use it.
@@ -522,6 +522,16 @@ Type ConstraintSystem::getCaughtErrorType(CatchNode catchNode) {
522
522
return explicitCaughtType;
523
523
}
524
524
525
+ return Type ();
526
+ }
527
+
528
+ Type ConstraintSystem::getCaughtErrorType (CatchNode catchNode) {
529
+ ASTContext &ctx = getASTContext ();
530
+
531
+ // If we have an explicit caught error type for this node, use it.
532
+ if (auto explicitCaughtType = getExplicitCaughtErrorType (catchNode))
533
+ return explicitCaughtType;
534
+
525
535
// Retrieve the thrown error type of a closure.
526
536
// FIXME: This will need to change when we do inference of thrown error
527
537
// types in closures.
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-emit-silgen %s -verify
2
+
3
+ // https://github.com/swiftlang/swift/issues/77295 - Make sure this compiles.
4
+ extension Optional {
5
+ func foo< E: Error > ( orThrow error: @autoclosure ( ) -> E ) throws ( E) -> Wrapped {
6
+ switch self {
7
+ case . none:
8
+ throw error ( )
9
+ case . some( let wrapped) :
10
+ wrapped
11
+ }
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments