Skip to content

Commit f85cb1c

Browse files
authored
Merge pull request #69684 from tbkka/tbkka-better-unexpected-nullable-message
Clarify the error we emit when we see an unexpected null pointer
2 parents 1a19193 + 079c83b commit f85cb1c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

stdlib/public/runtime/DynamicCast.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ static HeapObject * getNonNullSrcObject(OpaqueValue *srcValue,
126126

127127
std::string srcTypeName = nameForMetadata(srcType);
128128
std::string destTypeName = nameForMetadata(destType);
129-
const char * const msg = "Found unexpected null pointer value"
130-
" while trying to cast value of type '%s' (%p)"
131-
" to '%s' (%p)%s\n";
129+
const char * const msg = "Found a null pointer in a value of type '%s' (%p)."
130+
" Non-Optional values are not allowed to hold null pointers."
131+
" (Detected while casting to '%s' (%p))%s\n";
132132
if (runtime::bincompat::useLegacyPermissiveObjCNullSemanticsInCasting()) {
133133
// In backwards compatibility mode, this code will warn and return the null
134134
// reference anyway: If you examine the calls to the function, you'll see

test/Casting/CastTraps.swift.gyb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ CastTrapsTestSuite.test("${t1}__${t2}")
107107
protocol P2 {}
108108
if #available(SwiftStdlib 5.5, *) {
109109
CastTrapsTestSuite.test("Unexpected null")
110-
.crashOutputMatches("Found unexpected null pointer value while trying to cast value of type '")
110+
.crashOutputMatches("Found a null pointer in a value of type '")
111111
.crashOutputMatches("Foo'")
112-
.crashOutputMatches(" to '")
112+
.crashOutputMatches("(Detected while casting to '")
113113
.crashOutputMatches("P2'")
114114
.code
115115
{
@@ -127,9 +127,8 @@ CastTrapsTestSuite.test("Unexpected null")
127127
#if _runtime(_ObjC)
128128
if #available(SwiftStdlib 5.5, *) {
129129
CastTrapsTestSuite.test("Unexpected Obj-C null")
130-
.crashOutputMatches("Found unexpected null pointer value while trying to cast value of type '")
131-
.crashOutputMatches("NSObject'")
132-
.crashOutputMatches(" to '")
130+
.crashOutputMatches("Found a null pointer in a value of type 'NSObject'")
131+
.crashOutputMatches("(Detected while casting to '")
133132
.crashOutputMatches("P2'")
134133
.code
135134
{

0 commit comments

Comments
 (0)