Skip to content

Commit 7289baa

Browse files
committed
Sema: Respect TVO_CanBindToPack
1 parent 3adb1dd commit 7289baa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,6 +4204,14 @@ ConstraintSystem::matchTypesBindTypeVar(
42044204
}
42054205
}
42064206

4207+
if (type->is<PackType>() || type->is<PackArchetypeType>()) {
4208+
if (!typeVar->getImpl().canBindToPack())
4209+
return getTypeMatchFailure(locator);
4210+
} else if (!type->is<PlaceholderType>()) {
4211+
if (typeVar->getImpl().canBindToPack())
4212+
return getTypeMatchFailure(locator);
4213+
}
4214+
42074215
// We do not allow keypaths to go through AnyObject. Let's create a fix
42084216
// so this can be diagnosed later.
42094217
if (auto loc = typeVar->getImpl().getLocator()) {
@@ -6288,6 +6296,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
62886296
// trivially solved.
62896297
return getTypeMatchSuccess();
62906298
}
6299+
6300+
// If exactly one of the type variables can bind to an pack, we
6301+
// can't merge these two type variables.
6302+
if (rep1->getImpl().canBindToPack()
6303+
!= rep2->getImpl().canBindToPack())
6304+
return getTypeMatchFailure(locator);
62916305
}
62926306

62936307
switch (kind) {

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ void ConstraintSystem::assignFixedType(TypeVariableType *typeVar, Type type,
200200
return;
201201

202202
if (!type->isTypeVariableOrMember()) {
203+
if (type->is<PackType>() || type->is<PackArchetypeType>()) {
204+
assert(typeVar->getImpl().canBindToPack());
205+
} else if (!type->is<PlaceholderType>()) {
206+
assert(!typeVar->getImpl().canBindToPack());
207+
}
208+
203209
// If this type variable represents a literal, check whether we picked the
204210
// default literal type. First, find the corresponding protocol.
205211
//

0 commit comments

Comments
 (0)