Skip to content

[ConstraintSystem] Handle invalid pack element bindings during PackElementOf simplification. #64110

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 1 commit into from
Mar 5, 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
17 changes: 13 additions & 4 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8804,12 +8804,21 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,

// This constraint only exists to vend bindings.
auto *packEnv = DC->getGenericEnvironmentOfContext();
if ((!elementType->hasElementArchetype() && packType->isEqual(elementType)) ||
packType->isEqual(packEnv->mapElementTypeIntoPackContext(elementType))) {

// Map element archetypes to the pack context to check for equality.
if (elementType->hasElementArchetype()) {
auto mappedPack = packEnv->mapElementTypeIntoPackContext(elementType);
return (packType->isEqual(mappedPack) ?
SolutionKind::Solved : SolutionKind::Error);
}

// Pack expansions can have concrete pattern types. In this case, the pack
// type and element type will be equal.
if (packType->isEqual(elementType)) {
return SolutionKind::Solved;
} else {
return SolutionKind::Error;
}

return SolutionKind::Error;
}

static bool isForKeyPathSubscript(ConstraintSystem &cs,
Expand Down
4 changes: 4 additions & 0 deletions test/Constraints/pack-expansion-expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ func generateTuple<each T : Generatable>() -> (repeat each T) {

return (repeat (each T).generate())
}

func packElementInvalidBinding<each T>(_ arg: repeat each T) {
_ = (repeat print(each arg))
}