@@ -2125,7 +2125,9 @@ class TupleMatcher {
2125
2125
const auto &elt1 = tuple1->getElement(i);
2126
2126
const auto &elt2 = tuple2->getElement(i);
2127
2127
2128
- if (elt1.hasName() && elt1.getName() != elt2.getName())
2128
+ // FIXME: The fact that this isn't symmetric is wrong since this logic
2129
+ // is called for bind and equal constraints...
2130
+ if (elt2.hasName() && elt1.getName() != elt2.getName())
2129
2131
return true;
2130
2132
2131
2133
pairs.emplace_back(elt1.getType(), elt2.getType(), i, i);
@@ -3502,21 +3504,12 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
3502
3504
// FIXME: We should check value ownership too, but it's not completely
3503
3505
// trivial because of inout-to-pointer conversions.
3504
3506
3505
- // For equality contravariance doesn't matter, but let's make sure
3506
- // that types are matched in original order because that is important
3507
- // when function types are equated as part of pattern matching.
3508
- auto paramType1 = kind == ConstraintKind::Equal ? func1Param.getOldType()
3509
- : func2Param.getOldType();
3510
-
3511
- auto paramType2 = kind == ConstraintKind::Equal ? func2Param.getOldType()
3512
- : func1Param.getOldType();
3513
-
3514
- // Compare the parameter types.
3515
- auto result = matchTypes(paramType1, paramType2, subKind, subflags,
3516
- (func1Params.size() == 1
3517
- ? argumentLocator
3518
- : argumentLocator.withPathElement(
3519
- LocatorPathElt::TupleElement(i))));
3507
+ // Compare the parameter types, taking contravariance into account.
3508
+ auto result = matchTypes(
3509
+ func2Param.getOldType(), func1Param.getOldType(), subKind, subflags,
3510
+ (func1Params.size() == 1 ? argumentLocator
3511
+ : argumentLocator.withPathElement(
3512
+ LocatorPathElt::TupleElement(i))));
3520
3513
if (result.isFailure())
3521
3514
return result;
3522
3515
}
@@ -6356,7 +6349,7 @@ bool ConstraintSystem::repairFailures(
6356
6349
if (auto *OA = var->getAttrs().getAttribute<ReferenceOwnershipAttr>())
6357
6350
ROK = OA->get();
6358
6351
6359
- if (!rhs ->getOptionalObjectType() &&
6352
+ if (!lhs ->getOptionalObjectType() &&
6360
6353
optionalityOf(ROK) == ReferenceOwnershipOptionality::Required) {
6361
6354
conversionsOrFixes.push_back(
6362
6355
AllowNonOptionalWeak::create(*this, getConstraintLocator(NP)));
@@ -14298,8 +14291,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
14298
14291
if (recordFix(fix))
14299
14292
return SolutionKind::Error;
14300
14293
14301
- (void)matchTypes(type1, OptionalType::get(type2),
14302
- ConstraintKind::Equal,
14294
+ // NOTE: The order here is important! Pattern matching equality is
14295
+ // not symmetric (we need to fix that either by using a different
14296
+ // constraint, or actually making it symmetric).
14297
+ (void)matchTypes(OptionalType::get(type1), type2, ConstraintKind::Equal,
14303
14298
TypeMatchFlags::TMF_ApplyingFix, locator);
14304
14299
14305
14300
return SolutionKind::Solved;
0 commit comments