File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -3362,6 +3362,10 @@ class ConstraintSystem {
33623362 // / Undo the above change.
33633363 void removePotentialThrowSite (CatchNode catchNode);
33643364
3365+ // / Retrieve the explicit caught error type for the given catch node, without
3366+ // / attempting any inference.
3367+ Type getExplicitCaughtErrorType (CatchNode catchNode);
3368+
33653369 // / Determine the caught error type for the given catch node.
33663370 Type getCaughtErrorType (CatchNode node);
33673371
Original file line number Diff line number Diff line change @@ -969,7 +969,7 @@ class SyntacticElementConstraintGenerator
969969 auto throwLoc = throwStmt->getThrowLoc ();
970970 Type errorType;
971971 if (auto catchNode = ASTScope::lookupCatchNode (module , throwLoc))
972- errorType = catchNode. getExplicitCaughtType ( cs.getASTContext () );
972+ errorType = cs.getExplicitCaughtErrorType (catchNode );
973973
974974 if (!errorType) {
975975 if (!cs.getASTContext ().getErrorDecl ()) {
Original file line number Diff line number Diff line change @@ -511,7 +511,7 @@ void ConstraintSystem::recordPotentialThrowSite(
511511 recordPotentialThrowSite (catchNode, site);
512512}
513513
514- Type ConstraintSystem::getCaughtErrorType (CatchNode catchNode) {
514+ Type ConstraintSystem::getExplicitCaughtErrorType (CatchNode catchNode) {
515515 ASTContext &ctx = getASTContext ();
516516
517517 // If there is an explicit caught type for this node, use it.
@@ -522,6 +522,16 @@ Type ConstraintSystem::getCaughtErrorType(CatchNode catchNode) {
522522 return explicitCaughtType;
523523 }
524524
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+
525535 // Retrieve the thrown error type of a closure.
526536 // FIXME: This will need to change when we do inference of thrown error
527537 // 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