Skip to content

Commit 2df72f6

Browse files
committed
[ConstraintSystem] Strip pack expansions off of pack reference types in
getUnopenedTypeOfReference.
1 parent a2346db commit 2df72f6

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,6 @@ void PotentialBindings::infer(Constraint *constraint) {
14281428
// Produce a potential binding to the opened element archetype corresponding
14291429
// to the pack type.
14301430
packType = packType->mapTypeOutOfContext();
1431-
if (auto *expansion = packType->getAs<PackExpansionType>())
1432-
packType = expansion->getPatternType();
1433-
14341431
auto *elementEnv = openedElement->getGenericEnvironment();
14351432
auto elementType = elementEnv->mapPackTypeIntoElementContext(packType);
14361433
addPotentialBinding({elementType, AllowedBindingKind::Exact, constraint});

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,8 +3012,7 @@ namespace {
30123012
Type packType;
30133013
if (!expr->getPackElements().empty()) {
30143014
auto packReference = expr->getPackElements().front()->getPackRefExpr();
3015-
packType = CS.simplifyType(CS.getType(packReference))
3016-
->castTo<PackExpansionType>()->getPatternType();
3015+
packType = CS.simplifyType(CS.getType(packReference));
30173016
} else {
30183017
// FIXME: The generic environment needs to be per-shape-class.
30193018
llvm::SmallVector<GenericEnvironment::PackElementBinding, 2> bindings;

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8613,8 +8613,6 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
86138613

86148614
// This constraint only exists to vend bindings.
86158615
auto *packEnv = DC->getGenericEnvironmentOfContext();
8616-
if (auto *expansion = packType->getAs<PackExpansionType>())
8617-
packType = expansion->getPatternType();
86188616
if (packType->isEqual(packEnv->mapElementTypeIntoPackContext
86198617
(elementType->mapTypeOutOfContext()))) {
86208618
return SolutionKind::Solved;

lib/Sema/ConstraintSystem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,10 @@ Type ConstraintSystem::getUnopenedTypeOfReference(
12821282
Type requestedType =
12831283
getType(value)->getWithoutSpecifierType()->getReferenceStorageReferent();
12841284

1285+
// Strip pack expansion types off of pack references.
1286+
if (auto *expansion = requestedType->getAs<PackExpansionType>())
1287+
requestedType = expansion->getPatternType();
1288+
12851289
// Adjust the type for concurrency if requested.
12861290
if (adjustForPreconcurrency)
12871291
requestedType = adjustVarTypeForConcurrency(

test/Constraints/variadic_generic_functions.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ func invalidPacks() {
2727
}
2828

2929
func call() {
30-
func multipleParameters<T...>(xs: T..., ys: T...) -> (T...) { return (_: xs) }
30+
func multipleParameters<T...>(xs: T..., ys: T...) -> (T...) {
31+
return ((each xs)...)
32+
}
3133
multipleParameters()
3234

3335
let x: (_: String) = multipleParameters(xs: "", ys: "")
3436
let (one, two) = multipleParameters(xs: "", 5.0, ys: "", 5.0)
3537
multipleParameters(xs: "", 5.0, ys: 5.0, "") // expected-error {{type of expression is ambiguous without more context}}
3638

37-
func multipleSequences<T..., U...>(xs: T..., ys: U...) -> (T...) { return (_: ys) }
38-
// expected-error@-1 {{cannot convert return expression of type '(U...)' to return type '(T...)'}}
39+
func multipleSequences<T..., U...>(xs: T..., ys: U...) -> (T...) {
40+
return ((each ys)...)
41+
// expected-error@-1 {{cannot convert return expression of type '(U...)' to return type '(T...)'}}
42+
}
3943

4044
multipleSequences()
4145
_ = multipleSequences(xs: "", ys: "")

0 commit comments

Comments
 (0)