@@ -4196,6 +4196,16 @@ bool Metadata::satisfiesClassConstraint() const {
4196
4196
}
4197
4197
4198
4198
#if !NDEBUG
4199
+ static bool referencesAnonymousContext (Demangle::Node *node) {
4200
+ if (node->getKind () == Demangle::Node::Kind::AnonymousContext)
4201
+ return true ;
4202
+ for (unsigned i = 0 , e = node->getNumChildren (); i < e; ++i)
4203
+ if (referencesAnonymousContext (node->getChild (i)))
4204
+ return true ;
4205
+
4206
+ return false ;
4207
+ }
4208
+
4199
4209
void swift::verifyMangledNameRoundtrip (const Metadata *metadata) {
4200
4210
// Enable verification when a special environment variable is set.
4201
4211
// Some metatypes crash when going through the mangler or demangler. A
@@ -4211,12 +4221,17 @@ void swift::verifyMangledNameRoundtrip(const Metadata *metadata) {
4211
4221
4212
4222
Demangle::Demangler Dem;
4213
4223
auto node = _swift_buildDemanglingForMetadata (metadata, Dem);
4224
+ // If the mangled node involves types in an AnonymousContext, then by design,
4225
+ // it cannot be looked up by name.
4226
+ if (referencesAnonymousContext (node))
4227
+ return ;
4228
+
4214
4229
auto mangledName = Demangle::mangleNode (node);
4215
4230
auto result = _getTypeByMangledName (mangledName,
4216
4231
[](unsigned , unsigned ){ return nullptr ; });
4217
4232
if (metadata != result)
4218
4233
swift::warning (RuntimeErrorFlagNone,
4219
- " Metadata mangled name failed to roundtrip: %p -> %s -> %p" ,
4234
+ " Metadata mangled name failed to roundtrip: %p -> %s -> %p\n " ,
4220
4235
metadata, mangledName.c_str (), (const Metadata *)result);
4221
4236
}
4222
4237
#endif
0 commit comments