Skip to content

Commit 5d3984e

Browse files
[NFC] Flip polarity of matchFunctionRepresentations.
The existing polarity is sufficiently confusing that it has an explanatory comment at a return statement.
1 parent 7fb4815 commit 5d3984e

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,8 +1558,7 @@ isConversionAllowedBetween(FunctionTypeRepresentation rep1,
15581558
return rep1 == rep2;
15591559
}
15601560

1561-
// Returns 'false' (i.e. no error) if it is legal to match functions with the
1562-
// corresponding function type representations and the given match kind.
1561+
/// Returns true if `constraint rep1 rep2` is satisfied.
15631562
static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
15641563
FunctionTypeRepresentation rep2,
15651564
ConstraintKind kind,
@@ -1569,16 +1568,14 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
15691568
case ConstraintKind::BindParam:
15701569
case ConstraintKind::BindToPointerType:
15711570
case ConstraintKind::Equal:
1572-
return rep1 != rep2;
1571+
return rep1 == rep2;
15731572

15741573
case ConstraintKind::Subtype: {
15751574
auto last = locator.last();
15761575
if (!(last && last->is<LocatorPathElt::FunctionArgument>()))
1577-
return false;
1578-
1579-
// Inverting the result because matchFunctionRepresentations
1580-
// returns false in conversions are allowed.
1581-
return !isConversionAllowedBetween(rep1, rep2);
1576+
return true;
1577+
1578+
return isConversionAllowedBetween(rep1, rep2);
15821579
}
15831580

15841581
case ConstraintKind::OpaqueUnderlyingType:
@@ -1609,7 +1606,7 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
16091606
case ConstraintKind::OneWayEqual:
16101607
case ConstraintKind::OneWayBindParam:
16111608
case ConstraintKind::DefaultClosureType:
1612-
return false;
1609+
return true;
16131610
}
16141611

16151612
llvm_unreachable("Unhandled ConstraintKind in switch.");
@@ -1902,9 +1899,9 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
19021899
return getTypeMatchFailure(locator);
19031900
}
19041901

1905-
if (matchFunctionRepresentations(func1->getExtInfo().getRepresentation(),
1906-
func2->getExtInfo().getRepresentation(),
1907-
kind, locator)) {
1902+
if (!matchFunctionRepresentations(func1->getExtInfo().getRepresentation(),
1903+
func2->getExtInfo().getRepresentation(),
1904+
kind, locator)) {
19081905
return getTypeMatchFailure(locator);
19091906
}
19101907

0 commit comments

Comments
 (0)