Skip to content

[Strict memory safety] Lift "unsafe" in pattern match expressions #81675

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

Merged
merged 2 commits into from
May 21, 2025

Conversation

DougGregor
Copy link
Member

When an "unsafe" expression is used as the case expression, lift it up so it also covers the synthesized matching expression (=~). This eliminates some unsuppressible strict memory safety warnings.

While here, clean up the error messages for call arguments a bit so we show the proper types.

Fixes rdar://151731850.

When an "unsafe" expression is used as the case expression, lift it up
so it also covers the synthesized matching expression (`=~`). This
eliminates some unsuppressible strict memory safety warnings.

Fixes rdar://151731850.
Use the argument type rather than the (potentially generic) parameter type.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Comment on lines +771 to +778
auto subExpr = EP->getSubExpr();

// Pull off the outer "unsafe" expression.
UnsafeExpr *unsafeExpr = dyn_cast<UnsafeExpr>(subExpr);
if (unsafeExpr) {
subExpr = unsafeExpr->getSubExpr();
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can UnsafeExpr be wrapped in an IdentityExpr?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm. It's possible that we could have a try unsafe or similar here.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, that is broken, but I'm going to file a follow-up bug for myself because the try unsafe case is annoyingly hard to fix without breaking internal invariants.

@DougGregor DougGregor merged commit 689491c into swiftlang:main May 21, 2025
3 checks passed
@DougGregor DougGregor deleted the unsafe-pattern-match branch May 21, 2025 21:47
hamishknight added a commit to hamishknight/swift that referenced this pull request May 22, 2025
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.

2 participants