Skip to content

Commit 0b8927c

Browse files
committed
Sema: Respect TVO_CanBindToPack
1 parent 76103ce commit 0b8927c

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
@@ -4307,6 +4307,14 @@ ConstraintSystem::matchTypesBindTypeVar(
43074307
}
43084308
}
43094309

4310+
if (type->is<PackType>() || type->is<PackArchetypeType>()) {
4311+
if (!typeVar->getImpl().canBindToPack())
4312+
return getTypeMatchFailure(locator);
4313+
} else if (!type->is<PlaceholderType>()) {
4314+
if (typeVar->getImpl().canBindToPack())
4315+
return getTypeMatchFailure(locator);
4316+
}
4317+
43104318
// We do not allow keypaths to go through AnyObject. Let's create a fix
43114319
// so this can be diagnosed later.
43124320
if (auto loc = typeVar->getImpl().getLocator()) {
@@ -6536,6 +6544,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
65366544
// trivially solved.
65376545
return getTypeMatchSuccess();
65386546
}
6547+
6548+
// If exactly one of the type variables can bind to an pack, we
6549+
// can't merge these two type variables.
6550+
if (rep1->getImpl().canBindToPack()
6551+
!= rep2->getImpl().canBindToPack())
6552+
return getTypeMatchFailure(locator);
65396553
}
65406554

65416555
switch (kind) {

lib/Sema/ConstraintSystem.cpp

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

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

0 commit comments

Comments
 (0)