Skip to content

Commit 8def4d8

Browse files
committed
[Type checker] Factor out "isBindable" check for matchTypes. NFC
Thanks to Pavel (@xedin) for the feedback.
1 parent 6e3eeb6 commit 8def4d8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,13 @@ static void enumerateOptionalConversionRestrictions(
13751375
}
13761376
}
13771377

1378+
/// Determine whether we can bind the given type variable to the given
1379+
/// fixed type.
1380+
static bool isBindable(TypeVariableType *typeVar, Type type) {
1381+
return !ConstraintSystem::typeVarOccursInType(typeVar, type) &&
1382+
!type->is<DependentMemberType>();
1383+
}
1384+
13781385
ConstraintSystem::SolutionKind
13791386
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
13801387
TypeMatchOptions flags,
@@ -1480,8 +1487,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
14801487
// Simplify the right-hand type and perform the "occurs" check.
14811488
typeVar1 = getRepresentative(typeVar1);
14821489
type2 = simplifyType(type2, flags);
1483-
if (typeVarOccursInType(typeVar1, type2) ||
1484-
type2->is<DependentMemberType>())
1490+
if (!isBindable(typeVar1, type2))
14851491
return formUnsolvedResult();
14861492

14871493
// Equal constraints allow mixed LValue/RValue bindings, but
@@ -1531,8 +1537,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
15311537
// Simplify the left-hand type and perform the "occurs" check.
15321538
typeVar2 = getRepresentative(typeVar2);
15331539
type1 = simplifyType(type1, flags);
1534-
if (typeVarOccursInType(typeVar2, type1) ||
1535-
type1->is<DependentMemberType>())
1540+
if (!isBindable(typeVar2, type1))
15361541
return formUnsolvedResult();
15371542

15381543
// Equal constraints allow mixed LValue/RValue bindings, but
@@ -1564,8 +1569,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
15641569
// Simplify the left-hand type and perform the "occurs" check.
15651570
typeVar2 = getRepresentative(typeVar2);
15661571
type1 = simplifyType(type1, flags);
1567-
if (typeVarOccursInType(typeVar2, type1) ||
1568-
type1->is<DependentMemberType>())
1572+
if (!isBindable(typeVar2, type1))
15691573
return formUnsolvedResult();
15701574

15711575
if (auto *iot = type1->getAs<InOutType>()) {
@@ -1578,8 +1582,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
15781582
// Simplify the right-hand type and perform the "occurs" check.
15791583
typeVar1 = getRepresentative(typeVar1);
15801584
type2 = simplifyType(type2, flags);
1581-
if (typeVarOccursInType(typeVar1, type2) ||
1582-
type2->is<DependentMemberType>())
1585+
if (!isBindable(typeVar1, type2))
15831586
return formUnsolvedResult();
15841587

15851588
if (auto *lvt = type2->getAs<LValueType>()) {

0 commit comments

Comments
 (0)