Skip to content

ASTDemangler: Add support for member types of opaque result types #31989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,20 +609,35 @@ Type ASTBuilder::createGenericTypeParameterType(unsigned depth,

Type ASTBuilder::createDependentMemberType(StringRef member,
Type base) {
if (!base->isTypeParameter())
return Type();
auto identifier = Ctx.getIdentifier(member);

if (auto *archetype = base->getAs<ArchetypeType>()) {
if (archetype->hasNestedType(identifier))
return archetype->getNestedType(identifier);

}

if (base->isTypeParameter()) {
return DependentMemberType::get(base, identifier);
}

return DependentMemberType::get(base, Ctx.getIdentifier(member));
return Type();
}

Type ASTBuilder::createDependentMemberType(StringRef member,
Type base,
ProtocolDecl *protocol) {
if (!base->isTypeParameter())
return Type();
auto identifier = Ctx.getIdentifier(member);

if (auto assocType = protocol->getAssociatedType(Ctx.getIdentifier(member)))
return DependentMemberType::get(base, assocType);
if (auto *archetype = base->getAs<ArchetypeType>()) {
if (archetype->hasNestedType(identifier))
return archetype->getNestedType(identifier);
}

if (base->isTypeParameter()) {
if (auto assocType = protocol->getAssociatedType(identifier))
return DependentMemberType::get(base, assocType);
}

return Type();
}
Expand Down
8 changes: 8 additions & 0 deletions test/TypeDecoder/opaque_return_type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ extension Int: P {}
func foo() -> some P { return 0 }
var prop: some P { return 0 }

func bar() -> some Sequence { return [] }

// DEMANGLE: $s18opaque_return_type3fooQryFQOyQo_
// CHECK: some P

// DEMANGLE: $s18opaque_return_type4propQrvpQOyQo_
// CHECK: some P

// DEMANGLE: $s18opaque_return_type3barQryFQOyQo_
// CHECK: some Sequence

// DEMANGLE: $s18opaque_return_type3barQryFQOyQo_7ElementSTQxD
// CHECK: (some Sequence).Element