Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CS] Map caught error type into context #80248

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Mar 24, 2025

Factor out ConstraintSystem::getExplicitCaughtErrorType from getCaughtErrorType. Then use this for the contextual type for a throw syntactic element.

rdar://139000351
Resolves #77295

Factor out `ConstraintSystem::getExplicitCaughtErrorType` from 
`getCaughtErrorType`. Then use this for the contextual
type for a `throw` syntactic element.

rdar://139000351
@hamishknight
Copy link
Contributor Author

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hamishknight hamishknight enabled auto-merge March 24, 2025 22:34
@@ -969,7 +969,7 @@ class SyntacticElementConstraintGenerator
auto throwLoc = throwStmt->getThrowLoc();
Type errorType;
if (auto catchNode = ASTScope::lookupCatchNode(module, throwLoc))
errorType = catchNode.getExplicitCaughtType(cs.getASTContext());
errorType = cs.getExplicitCaughtErrorType(catchNode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only note here is use of DC in existing code. Maybe we should propagate dc down explicitly to avoid problems in the future because DC in ConstraintSystem during solving could be difference from DC during constraint generation unfortunately...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, fortunately in this case being in a closure doesn't affect the result of mapping into context, but yeah I agree we ought to be passing the DeclContext down

@hamishknight hamishknight merged commit a84b53f into swiftlang:main Mar 25, 2025
4 of 5 checks passed
@hamishknight hamishknight deleted the fix-error-type branch March 25, 2025 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typed-throws invalid diagnostic
3 participants