Skip to content

[ConstraintSystem] openOpaqueType: remove logic that duplicates bindArchetypesFromContext #64676

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
merged 2 commits into from
Mar 29, 2023
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: 3 additions & 12 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,22 +1009,11 @@ Type ConstraintSystem::openOpaqueType(OpaqueTypeArchetypeType *opaque,
// underlying return type.
auto opaqueLocator = locator.withPathElement(
LocatorPathElt::OpenedOpaqueArchetype(opaqueDecl));

OpenedTypeMap replacements;
openGeneric(DC, opaqueDecl->getOpaqueInterfaceGenericSignature(),
opaqueLocator, replacements);

// If there is an outer generic signature, bind the outer parameters based
// on the substitutions in the opaque type.
auto subs = opaque->getSubstitutions();
if (auto genericSig = subs.getGenericSignature()) {
for (auto *genericParamPtr : genericSig.getGenericParams()) {
Type genericParam(genericParamPtr);
addConstraint(
ConstraintKind::Bind, openType(genericParam, replacements),
genericParam.subst(subs), opaqueLocator);
}
}

recordOpenedTypes(opaqueLocatorKey, replacements);

return openType(opaque->getInterfaceType(), replacements);
Expand Down Expand Up @@ -1773,6 +1762,8 @@ static void bindArchetypesFromContext(
auto genericSig = parentDC->getGenericSignatureOfContext();
for (auto *paramTy : genericSig.getGenericParams()) {
Type contextTy = cs.DC->mapTypeIntoContext(paramTy);
if (paramTy->isParameterPack())
contextTy = PackType::getSingletonPackExpansion(contextTy);
bindPrimaryArchetype(paramTy, contextTy);
}

Expand Down
17 changes: 16 additions & 1 deletion test/Constraints/pack-expansion-expressions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature VariadicGenerics

// REQUIRES: asserts

Expand Down Expand Up @@ -318,3 +318,18 @@ func test_pack_expansion_specialization() {
_ = Data<Int, String>(42, "") // Ok
_ = Data<Int>(42, "") // expected-error {{extra argument in call}}
}

// rdar://107280056 - "Ambiguous without more context" with opaque return type + variadics
protocol Q {
associatedtype B
}

do {
struct G<each T>: Q {
typealias B = (repeat each T)
}

func f<each T>(_: repeat each T) -> some Q {
return G<repeat each T>() // Ok
}
}