@@ -1353,16 +1353,41 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
1353
1353
// corresponding function type representations and the given match kind.
1354
1354
static bool matchFunctionRepresentations (FunctionTypeRepresentation rep1,
1355
1355
FunctionTypeRepresentation rep2,
1356
- ConstraintKind kind) {
1356
+ ConstraintKind kind,
1357
+ ConstraintLocator *locator) {
1357
1358
switch (kind) {
1358
1359
case ConstraintKind::Bind:
1359
1360
case ConstraintKind::BindParam:
1360
1361
case ConstraintKind::BindToPointerType:
1361
1362
case ConstraintKind::Equal:
1362
1363
return rep1 != rep2;
1364
+
1365
+ case ConstraintKind::Subtype: {
1366
+ if (!locator->isLastElement <LocatorPathElt::FunctionArgument>())
1367
+ return false ;
1368
+
1369
+ auto isThin = [](FunctionTypeRepresentation rep) {
1370
+ return rep == FunctionTypeRepresentation::CFunctionPointer ||
1371
+ rep == FunctionTypeRepresentation::Thin;
1372
+ };
1373
+
1374
+ auto isThick = [](FunctionTypeRepresentation rep) {
1375
+ return rep == FunctionTypeRepresentation::Swift ||
1376
+ rep == swift::FunctionTypeRepresentation::Block;
1377
+ };
1378
+
1379
+ // Allowing conventions "thin" (c, thin) to "thick" (swift, block)
1380
+ if (isThin (rep1) && isThick (rep2))
1381
+ return false ;
1382
+
1383
+ // Allowing conventions "thick" (swift, block) to "thick" (swift, block)
1384
+ if (isThick (rep1) && isThick (rep2))
1385
+ return false ;
1386
+
1387
+ return rep1 != rep2;
1388
+ }
1363
1389
1364
1390
case ConstraintKind::OpaqueUnderlyingType:
1365
- case ConstraintKind::Subtype:
1366
1391
case ConstraintKind::Conversion:
1367
1392
case ConstraintKind::BridgingConversion:
1368
1393
case ConstraintKind::ArgumentConversion:
@@ -1657,7 +1682,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
1657
1682
1658
1683
if (matchFunctionRepresentations (func1->getExtInfo ().getRepresentation (),
1659
1684
func2->getExtInfo ().getRepresentation (),
1660
- kind)) {
1685
+ kind, getConstraintLocator (locator) )) {
1661
1686
return getTypeMatchFailure (locator);
1662
1687
}
1663
1688
0 commit comments