Skip to content

Clarify the error we emit when we see an unexpected null pointer #69684

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 Nov 7, 2023

Informal discussion suggests that the original wording wasn't obvious to everyone. Hopefully, this is clearer.

Old message: "Found unexpected null pointer value while trying to cast value of type '%s' to '%s'"

It seems folks didn't connect "null pointer" to "non-Optional value that came from Obj-C" and tended to focus on the destination type.

New message: "Non-Optional value of type '%s' holds a null pointer?! (Detected while casting to '%s')"

This de-emphasizes the target type of the cast and more clearly explains the actual problem.

@tbkka
Copy link
Contributor Author

tbkka commented Nov 7, 2023

@swift-ci Please test

@tbkka
Copy link
Contributor Author

tbkka commented Nov 7, 2023

@swift-ci Please test

" while trying to cast value of type '%s' (%p)"
" to '%s' (%p)%s\n";
const char * const msg = "Non-Optional value of type '%s' (%p)"
" holds a null pointer?!"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
" holds a null pointer?!"
" holds a null pointer, which is not allowed by the type system."

Thinking it's good to spell it out even more, in case someone doesn't understand why it's bad to have null in a non-optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revised message further:

Found a null pointer in a value of type '%s'. Non-Optional values are not allowed to hold null pointers. (Detected while casting to '%s')

@tbkka
Copy link
Contributor Author

tbkka commented Nov 8, 2023

@swift-ci Please test

@tbkka tbkka enabled auto-merge November 8, 2023 21:52
@tbkka tbkka merged commit f85cb1c into swiftlang:main Nov 9, 2023
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