Skip to content

Commit b021123

Browse files
authored
Merge pull request #64146 from hborla/shape-of-assertion
[ConstraintSystem] Don't propagate errors for invalid `DeclRef`s in the pattern of a pack expansion.
2 parents b9800fd + 721b846 commit b021123

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
@@ -8880,8 +8880,8 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
88808880

88818881
if (shouldAttemptFixes()) {
88828882
auto *loc = getConstraintLocator(locator);
8883-
auto *fix = AllowInvalidPackElement::create(*this, packType, loc);
8884-
if (!recordFix(fix))
8883+
if (elementType->isPlaceholder() ||
8884+
!recordFix(AllowInvalidPackElement::create(*this, packType, loc)))
88858885
return SolutionKind::Solved;
88868886
}
88878887

@@ -12980,6 +12980,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyShapeOfConstraint(
1298012980
return SolutionKind::Unsolved;
1298112981
};
1298212982

12983+
// Don't try computing the shape of a type variable.
12984+
if (type1->isTypeVariableOrMember())
12985+
return formUnsolved();
12986+
1298312987
// We can't compute a reduced shape if the input type still
1298412988
// contains type variables that might bind to pack archetypes.
1298512989
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)