Skip to content

ASTDemangler: Fix reconstruction of opaque result type defined in a constrained extension [5.3] #33709

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
15 changes: 5 additions & 10 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,16 @@ createSubstitutionMapFromGenericArgs(GenericSignature genericSig,
if (!genericSig)
return SubstitutionMap();

SmallVector<GenericTypeParamType *, 4> genericParams;
genericSig->forEachParam([&](GenericTypeParamType *gp, bool canonical) {
if (canonical)
genericParams.push_back(gp);
});
if (genericParams.size() != args.size())
if (genericSig->getGenericParams().size() != args.size())
return SubstitutionMap();

return SubstitutionMap::get(
genericSig,
[&](SubstitutableType *t) -> Type {
for (unsigned i = 0, e = genericParams.size(); i < e; ++i) {
if (t->isEqual(genericParams[i]))
return args[i];
}
auto *gp = cast<GenericTypeParamType>(t);
unsigned ordinal = genericSig->getGenericParamOrdinal(gp);
if (ordinal < args.size())
return args[ordinal];
return Type();
},
LookUpConformanceInModule(moduleDecl));
Expand Down
9 changes: 9 additions & 0 deletions test/TypeDecoder/opaque_return_type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ var prop: some P { return 0 }

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

struct G<T> {}

extension G where T == Int {
var baz: some P { return 0 }
}

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

Expand All @@ -21,5 +27,8 @@ func bar() -> some Sequence { return [] }
// DEMANGLE: $s18opaque_return_type3barQryFQOyQo_
// CHECK: some Sequence

// DEMANGLE: $s18opaque_return_type1GVAASiRszlE3bazQrvpQOySi_Qo_
// CHECK: some P

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