@@ -2165,7 +2165,9 @@ class TupleMatcher {
2165
2165
const auto &elt2 = tuple2->getElement(i);
2166
2166
2167
2167
if (inPatternMatchingContext) {
2168
- if (elt1.hasName() && elt1.getName() != elt2.getName())
2168
+ // FIXME: The fact that this isn't symmetric is wrong since this logic
2169
+ // is called for bind and equal constraints...
2170
+ if (elt2.hasName() && elt1.getName() != elt2.getName())
2169
2171
return true;
2170
2172
} else {
2171
2173
// If the names don't match, we have a conflict.
@@ -3523,21 +3525,12 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
3523
3525
// FIXME: We should check value ownership too, but it's not completely
3524
3526
// trivial because of inout-to-pointer conversions.
3525
3527
3526
- // For equality contravariance doesn't matter, but let's make sure
3527
- // that types are matched in original order because that is important
3528
- // when function types are equated as part of pattern matching.
3529
- auto paramType1 = kind == ConstraintKind::Equal ? func1Param.getOldType()
3530
- : func2Param.getOldType();
3531
-
3532
- auto paramType2 = kind == ConstraintKind::Equal ? func2Param.getOldType()
3533
- : func1Param.getOldType();
3534
-
3535
- // Compare the parameter types.
3536
- auto result = matchTypes(paramType1, paramType2, subKind, subflags,
3537
- (func1Params.size() == 1
3538
- ? argumentLocator
3539
- : argumentLocator.withPathElement(
3540
- LocatorPathElt::TupleElement(i))));
3528
+ // Compare the parameter types, taking contravariance into account.
3529
+ auto result = matchTypes(
3530
+ func2Param.getOldType(), func1Param.getOldType(), subKind, subflags,
3531
+ (func1Params.size() == 1 ? argumentLocator
3532
+ : argumentLocator.withPathElement(
3533
+ LocatorPathElt::TupleElement(i))));
3541
3534
if (result.isFailure())
3542
3535
return result;
3543
3536
}
@@ -6405,7 +6398,7 @@ bool ConstraintSystem::repairFailures(
6405
6398
if (auto *OA = var->getAttrs().getAttribute<ReferenceOwnershipAttr>())
6406
6399
ROK = OA->get();
6407
6400
6408
- if (!rhs ->getOptionalObjectType() &&
6401
+ if (!lhs ->getOptionalObjectType() &&
6409
6402
optionalityOf(ROK) == ReferenceOwnershipOptionality::Required) {
6410
6403
conversionsOrFixes.push_back(
6411
6404
AllowNonOptionalWeak::create(*this, getConstraintLocator(NP)));
@@ -14821,7 +14814,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
14821
14814
if (recordFix(fix))
14822
14815
return SolutionKind::Error;
14823
14816
14824
- (void)matchTypes(type1, OptionalType::get(type2), ConstraintKind::Equal,
14817
+ // NOTE: The order here is important! Pattern matching equality is
14818
+ // not symmetric (we need to fix that either by using a different
14819
+ // constraint, or actually making it symmetric).
14820
+ (void)matchTypes(OptionalType::get(type1), type2, ConstraintKind::Equal,
14825
14821
TypeMatchFlags::TMF_ApplyingFix, locator);
14826
14822
14827
14823
return SolutionKind::Solved;
0 commit comments