Skip to content

Commit cc0983e

Browse files
committed
Runtime: Fallback when _swift_getFieldAt fails to find field metadata.
Better to log the failure than fall off the edge of this function, which is expected to always invoke its callback once.
1 parent ff66b79 commit cc0983e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ void swift::_swift_getFieldAt(
11661166
if (typeInfo == nullptr) {
11671167
typeInfo = TypeInfo(&METADATA_SYM(EMPTY_TUPLE_MANGLING), {});
11681168
warning(0, "SWIFT RUNTIME BUG: unable to demangle type of field '%*s'. "
1169-
"mangled type name is '%*s'",
1169+
"mangled type name is '%*s'\n",
11701170
(int)name.size(), name.data(),
11711171
(int)typeName.size(), typeName.data());
11721172
}
@@ -1214,6 +1214,17 @@ void swift::_swift_getFieldAt(
12141214
return;
12151215
}
12161216
}
1217+
1218+
// If we failed to find the field descriptor metadata for the type, fall
1219+
// back to returning an empty tuple as a standin.
1220+
auto typeName = swift_getTypeName(base, /*qualified*/ true);
1221+
warning(0, "SWIFT RUNTIME BUG: unable to find field metadata for type '%*s'\n",
1222+
(int)typeName.length, typeName.data);
1223+
callback("unknown",
1224+
FieldType()
1225+
.withType(TypeInfo(&METADATA_SYM(EMPTY_TUPLE_MANGLING), {}))
1226+
.withIndirect(false)
1227+
.withWeak(false));
12171228
}
12181229

12191230
#define OVERRIDE_METADATALOOKUP COMPATIBILITY_OVERRIDE

0 commit comments

Comments
 (0)