Skip to content

Commit b8b62a2

Browse files
authored
Merge pull request #9433 from rudkx/better-fix-for-rdar31724272
Better fix for handling Equal constraints in matchTypes.
2 parents f7f31e2 + 08c1c98 commit b8b62a2

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,22 +1425,17 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
14251425
if (typeVarOccursInType(typeVar1, type2))
14261426
return formUnsolvedResult();
14271427

1428-
// Equal constraints allow mixed LValue/RValue bindings.
1428+
// Equal constraints allow mixed LValue/RValue bindings, but
1429+
// if we bind a type to a type variable that can bind to
1430+
// LValues as part of simplifying the Equal constraint we may
1431+
// later block a binding of the opposite "LValue-ness" to the
1432+
// same type variable that happens as part of simplifying
1433+
// another constraint.
14291434
if (kind == ConstraintKind::Equal) {
1430-
// If we could bind an LValue to the type variable, but the
1431-
// type that is already bound is not an LValue, defer
1432-
// simplifying the constraint since we may come along at a
1433-
// later time and attempt to bind the LValue type to this
1434-
// type variable.
1435-
if (typeVar1->getImpl().canBindToLValue()) {
1436-
if (!type2->isLValueType()) {
1437-
return formUnsolvedResult();
1438-
}
1439-
} else {
1440-
// If the type variable does not allow LValue bindings,
1441-
// get the RValue type.
1442-
type2 = type2->getRValueType();
1443-
}
1435+
if (typeVar1->getImpl().canBindToLValue())
1436+
return formUnsolvedResult();
1437+
1438+
type2 = type2->getRValueType();
14441439
}
14451440

14461441
// If the left-hand type variable cannot bind to an lvalue,
@@ -1480,22 +1475,17 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
14801475
if (typeVarOccursInType(typeVar2, type1))
14811476
return formUnsolvedResult();
14821477

1483-
// Equal constraints allow mixed LValue/RValue bindings.
1478+
// Equal constraints allow mixed LValue/RValue bindings, but
1479+
// if we bind a type to a type variable that can bind to
1480+
// LValues as part of simplifying the Equal constraint we may
1481+
// later block a binding of the opposite "LValue-ness" to the
1482+
// same type variable that happens as part of simplifying
1483+
// another constraint.
14841484
if (kind == ConstraintKind::Equal) {
1485-
// If we could bind an LValue to the type variable, but the
1486-
// type that is already bound is not an LValue, defer
1487-
// simplifying the constraint since we may come along at a
1488-
// later time and attempt to bind the LValue type to this
1489-
// type variable.
1490-
if (typeVar2->getImpl().canBindToLValue()) {
1491-
if (!type1->isLValueType()) {
1492-
return formUnsolvedResult();
1493-
}
1494-
} else {
1495-
// If the type variable does not allow LValue bindings,
1496-
// get the RValue type.
1497-
type1 = type1->getRValueType();
1498-
}
1485+
if (typeVar2->getImpl().canBindToLValue())
1486+
return formUnsolvedResult();
1487+
1488+
type1 = type1->getRValueType();
14991489
}
15001490

15011491
if (!typeVar2->getImpl().canBindToLValue() &&

0 commit comments

Comments
 (0)