Skip to content

[Runtime] Have swift_dynamicCast unwrap multiple levels of optionals in the source. #16772

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

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented May 22, 2018

The real work is done in checkDynamicCastFromOptional. This code tried to unwrap the source and returned the payload on success. It only did this once, so a type like Optional<Optional<Int>> would come out as Optional<Int> and then a cast to Int would fail.

This change makes checkDynamicCastFromOptional recursive, which makes it unwrap as many levels of Optional as it encounters.

Fixes rdar://problem/40171034 and SR-7664.

…in the source.

The real work is done in checkDynamicCastFromOptional. This code tried to unwrap the source and returned the payload on success. It only did this once, so a type like Optional<Optional<Int>> would come out as Optional<Int> and then a cast to Int would fail.

This change makes checkDynamicCastFromOptional recursive, which makes it unwrap as many levels of Optional as it encounters.

Fixes rdar://problem/40171034 and SR-7664.
@mikeash
Copy link
Contributor Author

mikeash commented May 22, 2018

@swift-ci please test

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

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

Nice catch!

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