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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/public/runtime/DynamicCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ static HeapObject * getNonNullSrcObject(OpaqueValue *srcValue,

std::string srcTypeName = nameForMetadata(srcType);
std::string destTypeName = nameForMetadata(destType);
const char * const msg = "Found unexpected null pointer value"
" while trying to cast value of type '%s' (%p)"
" to '%s' (%p)%s\n";
const char * const msg = "Found a null pointer in a value of type '%s' (%p)."
" Non-Optional values are not allowed to hold null pointers."
" (Detected while casting to '%s' (%p))%s\n";
if (runtime::bincompat::useLegacyPermissiveObjCNullSemanticsInCasting()) {
// In backwards compatibility mode, this code will warn and return the null
// reference anyway: If you examine the calls to the function, you'll see
Expand Down
9 changes: 4 additions & 5 deletions test/Casting/CastTraps.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ CastTrapsTestSuite.test("${t1}__${t2}")
protocol P2 {}
if #available(SwiftStdlib 5.5, *) {
CastTrapsTestSuite.test("Unexpected null")
.crashOutputMatches("Found unexpected null pointer value while trying to cast value of type '")
.crashOutputMatches("Found a null pointer in a value of type '")
.crashOutputMatches("Foo'")
.crashOutputMatches(" to '")
.crashOutputMatches("(Detected while casting to '")
.crashOutputMatches("P2'")
.code
{
Expand All @@ -127,9 +127,8 @@ CastTrapsTestSuite.test("Unexpected null")
#if _runtime(_ObjC)
if #available(SwiftStdlib 5.5, *) {
CastTrapsTestSuite.test("Unexpected Obj-C null")
.crashOutputMatches("Found unexpected null pointer value while trying to cast value of type '")
.crashOutputMatches("NSObject'")
.crashOutputMatches(" to '")
.crashOutputMatches("Found a null pointer in a value of type 'NSObject'")
.crashOutputMatches("(Detected while casting to '")
.crashOutputMatches("P2'")
.code
{
Expand Down