Skip to content

Commit 32e1d22

Browse files
authored
Merge pull request #31989 from slavapestov/demangle-nested-type-of-opaque-type
ASTDemangler: Add support for member types of opaque result types
2 parents fc7bdf8 + f5258ed commit 32e1d22

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,20 +609,35 @@ Type ASTBuilder::createGenericTypeParameterType(unsigned depth,
609609

610610
Type ASTBuilder::createDependentMemberType(StringRef member,
611611
Type base) {
612-
if (!base->isTypeParameter())
613-
return Type();
612+
auto identifier = Ctx.getIdentifier(member);
613+
614+
if (auto *archetype = base->getAs<ArchetypeType>()) {
615+
if (archetype->hasNestedType(identifier))
616+
return archetype->getNestedType(identifier);
617+
618+
}
619+
620+
if (base->isTypeParameter()) {
621+
return DependentMemberType::get(base, identifier);
622+
}
614623

615-
return DependentMemberType::get(base, Ctx.getIdentifier(member));
624+
return Type();
616625
}
617626

618627
Type ASTBuilder::createDependentMemberType(StringRef member,
619628
Type base,
620629
ProtocolDecl *protocol) {
621-
if (!base->isTypeParameter())
622-
return Type();
630+
auto identifier = Ctx.getIdentifier(member);
623631

624-
if (auto assocType = protocol->getAssociatedType(Ctx.getIdentifier(member)))
625-
return DependentMemberType::get(base, assocType);
632+
if (auto *archetype = base->getAs<ArchetypeType>()) {
633+
if (archetype->hasNestedType(identifier))
634+
return archetype->getNestedType(identifier);
635+
}
636+
637+
if (base->isTypeParameter()) {
638+
if (auto assocType = protocol->getAssociatedType(identifier))
639+
return DependentMemberType::get(base, assocType);
640+
}
626641

627642
return Type();
628643
}

test/TypeDecoder/opaque_return_type.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ extension Int: P {}
1010
func foo() -> some P { return 0 }
1111
var prop: some P { return 0 }
1212

13+
func bar() -> some Sequence { return [] }
14+
1315
// DEMANGLE: $s18opaque_return_type3fooQryFQOyQo_
1416
// CHECK: some P
1517

1618
// DEMANGLE: $s18opaque_return_type4propQrvpQOyQo_
1719
// CHECK: some P
20+
21+
// DEMANGLE: $s18opaque_return_type3barQryFQOyQo_
22+
// CHECK: some Sequence
23+
24+
// DEMANGLE: $s18opaque_return_type3barQryFQOyQo_7ElementSTQxD
25+
// CHECK: (some Sequence).Element

0 commit comments

Comments
 (0)