@@ -2157,7 +2157,9 @@ class TupleMatcher {
2157
2157
const auto &elt2 = tuple2->getElement(i);
2158
2158
2159
2159
if (inPatternMatchingContext) {
2160
- if (elt1.hasName() && elt1.getName() != elt2.getName())
2160
+ // FIXME: The fact that this isn't symmetric is wrong since this logic
2161
+ // is called for bind and equal constraints...
2162
+ if (elt2.hasName() && elt1.getName() != elt2.getName())
2161
2163
return true;
2162
2164
} else {
2163
2165
// If the names don't match, we have a conflict.
@@ -3515,21 +3517,12 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
3515
3517
// FIXME: We should check value ownership too, but it's not completely
3516
3518
// trivial because of inout-to-pointer conversions.
3517
3519
3518
- // For equality contravariance doesn't matter, but let's make sure
3519
- // that types are matched in original order because that is important
3520
- // when function types are equated as part of pattern matching.
3521
- auto paramType1 = kind == ConstraintKind::Equal ? func1Param.getOldType()
3522
- : func2Param.getOldType();
3523
-
3524
- auto paramType2 = kind == ConstraintKind::Equal ? func2Param.getOldType()
3525
- : func1Param.getOldType();
3526
-
3527
- // Compare the parameter types.
3528
- auto result = matchTypes(paramType1, paramType2, subKind, subflags,
3529
- (func1Params.size() == 1
3530
- ? argumentLocator
3531
- : argumentLocator.withPathElement(
3532
- LocatorPathElt::TupleElement(i))));
3520
+ // Compare the parameter types, taking contravariance into account.
3521
+ auto result = matchTypes(
3522
+ func2Param.getOldType(), func1Param.getOldType(), subKind, subflags,
3523
+ (func1Params.size() == 1 ? argumentLocator
3524
+ : argumentLocator.withPathElement(
3525
+ LocatorPathElt::TupleElement(i))));
3533
3526
if (result.isFailure())
3534
3527
return result;
3535
3528
}
@@ -6394,7 +6387,7 @@ bool ConstraintSystem::repairFailures(
6394
6387
if (auto *OA = var->getAttrs().getAttribute<ReferenceOwnershipAttr>())
6395
6388
ROK = OA->get();
6396
6389
6397
- if (!rhs ->getOptionalObjectType() &&
6390
+ if (!lhs ->getOptionalObjectType() &&
6398
6391
optionalityOf(ROK) == ReferenceOwnershipOptionality::Required) {
6399
6392
conversionsOrFixes.push_back(
6400
6393
AllowNonOptionalWeak::create(*this, getConstraintLocator(NP)));
@@ -14786,7 +14779,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
14786
14779
if (recordFix(fix))
14787
14780
return SolutionKind::Error;
14788
14781
14789
- (void)matchTypes(type1, OptionalType::get(type2), ConstraintKind::Equal,
14782
+ // NOTE: The order here is important! Pattern matching equality is
14783
+ // not symmetric (we need to fix that either by using a different
14784
+ // constraint, or actually making it symmetric).
14785
+ (void)matchTypes(OptionalType::get(type1), type2, ConstraintKind::Equal,
14790
14786
TypeMatchFlags::TMF_ApplyingFix, locator);
14791
14787
14792
14788
return SolutionKind::Solved;
0 commit comments