Skip to content

Commit 721b846

Browse files
committed
[ConstraintSystem] Don't propagate errors for invalid DeclRefs in the pattern
of a pack expansion.
1 parent edb980e commit 721b846

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/CSSimplify.cpp

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

88218821
if (shouldAttemptFixes()) {
88228822
auto *loc = getConstraintLocator(locator);
8823-
auto *fix = AllowInvalidPackElement::create(*this, packType, loc);
8824-
if (!recordFix(fix))
8823+
if (elementType->isPlaceholder() ||
8824+
!recordFix(AllowInvalidPackElement::create(*this, packType, loc)))
88258825
return SolutionKind::Solved;
88268826
}
88278827

@@ -12920,6 +12920,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyShapeOfConstraint(
1292012920
return SolutionKind::Unsolved;
1292112921
};
1292212922

12923+
// Don't try computing the shape of a type variable.
12924+
if (type1->isTypeVariableOrMember())
12925+
return formUnsolved();
12926+
1292312927
// We can't compute a reduced shape if the input type still
1292412928
// contains type variables that might bind to pack archetypes.
1292512929
SmallPtrSet<TypeVariableType *, 2> typeVars;

test/Constraints/pack-expansion-expressions.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,14 @@ func packElementInvalidBinding<each T>(_ arg: repeat each T) {
125125
repeat print(each x)
126126
// expected-error@-1 {{'each' cannot be applied to non-pack type 'Int'}}
127127
}
128+
129+
func copyIntoTuple<each T>(_ arg: repeat each T) -> (repeat each T) {
130+
return (repeat each arg)
131+
}
132+
func callCopyAndBind<T>(_ arg: repeat each T) {
133+
// expected-error@-1 {{'each' cannot be applied to non-pack type 'T'}}
134+
// expected-error@-2 {{variadic expansion 'T' must contain at least one variadic generic parameter}}
135+
136+
// Don't propagate errors for invalid declaration reference
137+
let result = copyIntoTuple(repeat each arg)
138+
}

0 commit comments

Comments
 (0)