Skip to content

Commit 7b01206

Browse files
authored
Merge pull request swiftlang#31990 from slavapestov/demangle-nested-type-of-opaque-type-5.3
ASTDemangler: Add support for member types of opaque result types [5.3]
2 parents 3de36cb + 8bca08c commit 7b01206

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
@@ -597,20 +597,35 @@ Type ASTBuilder::createGenericTypeParameterType(unsigned depth,
597597

598598
Type ASTBuilder::createDependentMemberType(StringRef member,
599599
Type base) {
600-
if (!base->isTypeParameter())
601-
return Type();
600+
auto identifier = Ctx.getIdentifier(member);
601+
602+
if (auto *archetype = base->getAs<ArchetypeType>()) {
603+
if (archetype->hasNestedType(identifier))
604+
return archetype->getNestedType(identifier);
605+
606+
}
607+
608+
if (base->isTypeParameter()) {
609+
return DependentMemberType::get(base, identifier);
610+
}
602611

603-
return DependentMemberType::get(base, Ctx.getIdentifier(member));
612+
return Type();
604613
}
605614

606615
Type ASTBuilder::createDependentMemberType(StringRef member,
607616
Type base,
608617
ProtocolDecl *protocol) {
609-
if (!base->isTypeParameter())
610-
return Type();
618+
auto identifier = Ctx.getIdentifier(member);
611619

612-
if (auto assocType = protocol->getAssociatedType(Ctx.getIdentifier(member)))
613-
return DependentMemberType::get(base, assocType);
620+
if (auto *archetype = base->getAs<ArchetypeType>()) {
621+
if (archetype->hasNestedType(identifier))
622+
return archetype->getNestedType(identifier);
623+
}
624+
625+
if (base->isTypeParameter()) {
626+
if (auto assocType = protocol->getAssociatedType(identifier))
627+
return DependentMemberType::get(base, assocType);
628+
}
614629

615630
return Type();
616631
}

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)