Skip to content

Conditionalize null ptr check when casting #35100

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

tbkka
Copy link
Contributor

@tbkka tbkka commented Dec 15, 2020

Background: We've noticed a lot of problems from Obj-C APIs that returned null
even though they were declared to never do so. These mismatches subvert Swift's
type system and can lead to hard-to-diagnose crashes much later in the program.
This fatal error was introduced into the primary casting function to help catch
such problems closer to the point where they occur so developers could more
easily identify and fix them.

However, there's been some concern about what this means for old binaries, so
we're considering a check here that would allow the old behavior in certain
cases yet to be determined. This PR adds the framework for such a check.

Resolves rdar://72323929

Background: We've noticed a lot of problems from Obj-C APIs that returned null
even though they were declared to never do so.  These mismatches subvert Swift's
type system and can lead to hard-to-diagnose crashes much later in the program.
This fatal error was introduced into the primary casting function to help catch
such problems closer to the point where they occur so developers could more
easily identify and fix them.

However, there's been some concern about what this means for old binaries, so
we're considering a check here that would allow the old behavior in certain
cases yet to be determined.  This PR adds the framework for such a check.

Resolves rdar://72323929
@tbkka tbkka requested a review from mikeash December 15, 2020 20:38
@tbkka
Copy link
Contributor Author

tbkka commented Dec 15, 2020

@swift-ci Please test and merge

destTypeName.c_str(), destType,
"");
} else {
swift::warning(/* flags = */ 0, msg,
Copy link
Contributor

Choose a reason for hiding this comment

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

This might end up firing too often, if this ends up getting hit in a loop or something. I don't think you need to do this yet, but in the future this may need a flag or count to limit how many times the warning is logged in a given process.

@tbkka
Copy link
Contributor Author

tbkka commented Dec 16, 2020

@swift-ci Please test and merge

@swift-ci swift-ci merged commit 32c5941 into swiftlang:main Dec 16, 2020
@tbkka tbkka deleted the tbkka/conditional-objc-check-rdar72323929 branch August 1, 2024 16:36
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.

3 participants