diff --git a/stdlib/public/runtime/MetadataLookup.cpp b/stdlib/public/runtime/MetadataLookup.cpp index 7693994d615..517e44976b7 100644 --- a/stdlib/public/runtime/MetadataLookup.cpp +++ b/stdlib/public/runtime/MetadataLookup.cpp @@ -747,8 +747,20 @@ public: // Figure out the various levels of generic parameters we have in // this type. std::vector genericParamCounts; - bool innermostIsGeneric = - _gatherGenericParameterCounts(typeDecl, genericParamCounts); + bool innermostIsGeneric; + + // If we have no parent given, try to form the whole type in one go. + if (!parent) { + innermostIsGeneric = !genericArgs.empty(); + if (innermostIsGeneric) { + genericParamCounts.push_back(genericArgs.size()); + } + // Otherwise, we'll need to steal the generic arguments from the parent + // type to build a nested type. + } else { + innermostIsGeneric = _gatherGenericParameterCounts(typeDecl, + genericParamCounts); + } bool isGeneric = !genericParamCounts.empty(); // Gather the generic arguments. diff --git a/test/stdlib/Mirror.swift b/test/stdlib/Mirror.swift index ff2a4cf0123..1f23fb3f433 100644 --- a/test/stdlib/Mirror.swift +++ b/test/stdlib/Mirror.swift @@ -782,4 +782,20 @@ mirrors.test("String.init") { expectEqual("42", String(reflecting: 42)) expectEqual("\"42\"", String(reflecting: "42")) } + +struct a { + enum c{} +} +class d {} +struct e { + var constraints: [Int: a.c] = [:] +} + +mirrors.test("field with generic nested type") { + let x = e() + + expectTrue(type(of: Mirror(reflecting: x).children.first!.value) + == [Int: a.c].self) +} + runAllTests()