@@ -1375,6 +1375,13 @@ static void enumerateOptionalConversionRestrictions(
1375
1375
}
1376
1376
}
1377
1377
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
+
1378
1385
ConstraintSystem::SolutionKind
1379
1386
ConstraintSystem::matchTypes (Type type1, Type type2, ConstraintKind kind,
1380
1387
TypeMatchOptions flags,
@@ -1480,8 +1487,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1480
1487
// Simplify the right-hand type and perform the "occurs" check.
1481
1488
typeVar1 = getRepresentative (typeVar1);
1482
1489
type2 = simplifyType (type2, flags);
1483
- if (typeVarOccursInType (typeVar1, type2) ||
1484
- type2->is <DependentMemberType>())
1490
+ if (!isBindable (typeVar1, type2))
1485
1491
return formUnsolvedResult ();
1486
1492
1487
1493
// Equal constraints allow mixed LValue/RValue bindings, but
@@ -1531,8 +1537,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1531
1537
// Simplify the left-hand type and perform the "occurs" check.
1532
1538
typeVar2 = getRepresentative (typeVar2);
1533
1539
type1 = simplifyType (type1, flags);
1534
- if (typeVarOccursInType (typeVar2, type1) ||
1535
- type1->is <DependentMemberType>())
1540
+ if (!isBindable (typeVar2, type1))
1536
1541
return formUnsolvedResult ();
1537
1542
1538
1543
// Equal constraints allow mixed LValue/RValue bindings, but
@@ -1564,8 +1569,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1564
1569
// Simplify the left-hand type and perform the "occurs" check.
1565
1570
typeVar2 = getRepresentative (typeVar2);
1566
1571
type1 = simplifyType (type1, flags);
1567
- if (typeVarOccursInType (typeVar2, type1) ||
1568
- type1->is <DependentMemberType>())
1572
+ if (!isBindable (typeVar2, type1))
1569
1573
return formUnsolvedResult ();
1570
1574
1571
1575
if (auto *iot = type1->getAs <InOutType>()) {
@@ -1578,8 +1582,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1578
1582
// Simplify the right-hand type and perform the "occurs" check.
1579
1583
typeVar1 = getRepresentative (typeVar1);
1580
1584
type2 = simplifyType (type2, flags);
1581
- if (typeVarOccursInType (typeVar1, type2) ||
1582
- type2->is <DependentMemberType>())
1585
+ if (!isBindable (typeVar1, type2))
1583
1586
return formUnsolvedResult ();
1584
1587
1585
1588
if (auto *lvt = type2->getAs <LValueType>()) {
0 commit comments