@@ -110,6 +110,12 @@ extern "C" const StructDescriptor NOMINAL_TYPE_DESCR_SYM(Sh);
110
110
// / Nominal type descriptor for Swift.String.
111
111
extern " C" const StructDescriptor NOMINAL_TYPE_DESCR_SYM (SS);
112
112
113
+ // If this returns `true`, then we will call `fatalError` when we encounter a
114
+ // null reference in a storage locaation whose type does not allow null.
115
+ static bool unexpectedNullIsFatal () {
116
+ return true ; // Placeholder for an upcoming check.
117
+ }
118
+
113
119
static HeapObject * getNonNullSrcObject (OpaqueValue *srcValue,
114
120
const Metadata *srcType,
115
121
const Metadata *destType) {
@@ -120,12 +126,21 @@ static HeapObject * getNonNullSrcObject(OpaqueValue *srcValue,
120
126
121
127
std::string srcTypeName = nameForMetadata (srcType);
122
128
std::string destTypeName = nameForMetadata (destType);
123
- swift::fatalError (/* flags = */ 0 ,
124
- " Found unexpected null pointer value"
129
+ const char *msg = " Found unexpected null pointer value"
125
130
" while trying to cast value of type '%s' (%p)"
126
- " to '%s' (%p)\n " ,
127
- srcTypeName.c_str (), srcType,
128
- destTypeName.c_str (), destType);
131
+ " to '%s' (%p)%s\n " ;
132
+ if (unexpectedNullIsFatal ()) {
133
+ swift::fatalError (/* flags = */ 0 , msg,
134
+ srcTypeName.c_str (), srcType,
135
+ destTypeName.c_str (), destType,
136
+ " " );
137
+ } else {
138
+ swift::warning (/* flags = */ 0 , msg,
139
+ srcTypeName.c_str (), srcType,
140
+ destTypeName.c_str (), destType,
141
+ " : Continuing with null object, but expect problems later." );
142
+ }
143
+ return object;
129
144
}
130
145
131
146
/* *****************************************************************************/
0 commit comments