2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -1437,10 +1437,16 @@ static bool isStringCompatiblePointerBaseType(TypeChecker &TC,
1437
1437
// / Determine whether the first type with the given number of optionals
1438
1438
// / is potentially more optional than the second type with its number of
1439
1439
// / optionals.
1440
- static bool isPotentiallyMoreOptionalThan (Type objType1,
1441
- unsigned numOptionals1,
1442
- Type objType2,
1443
- unsigned numOptionals2) {
1440
+ static bool isPotentiallyMoreOptionalThan (Type type1, Type type2) {
1441
+
1442
+ SmallVector<Type, 2 > optionals1;
1443
+ Type objType1 = type1->lookThroughAllOptionalTypes (optionals1);
1444
+ auto numOptionals1 = optionals1.size ();
1445
+
1446
+ SmallVector<Type, 2 > optionals2;
1447
+ type2->lookThroughAllOptionalTypes (optionals2);
1448
+ auto numOptionals2 = optionals2.size ();
1449
+
1444
1450
if (numOptionals1 <= numOptionals2 && !objType1->isTypeVariableOrMember ())
1445
1451
return false ;
1446
1452
@@ -1452,22 +1458,12 @@ static void enumerateOptionalConversionRestrictions(
1452
1458
Type type1, Type type2,
1453
1459
ConstraintKind kind, ConstraintLocatorBuilder locator,
1454
1460
llvm::function_ref<void (ConversionRestrictionKind)> fn) {
1455
- SmallVector<Type, 2 > optionals1;
1456
- Type objType1 = type1->lookThroughAllOptionalTypes (optionals1);
1457
-
1458
- SmallVector<Type, 2 > optionals2;
1459
- Type objType2 = type2->lookThroughAllOptionalTypes (optionals2);
1460
-
1461
- if (optionals1.empty () && optionals2.empty ())
1462
- return ;
1463
-
1464
1461
// Optional-to-optional.
1465
- if (!optionals1. empty () && !optionals2. empty ())
1462
+ if (type1-> getOptionalObjectType () && type2-> getOptionalObjectType ())
1466
1463
fn (ConversionRestrictionKind::OptionalToOptional);
1467
1464
1468
1465
// Inject a value into an optional.
1469
- if (isPotentiallyMoreOptionalThan (objType2, optionals2.size (),
1470
- objType1, optionals1.size ())) {
1466
+ if (isPotentiallyMoreOptionalThan (type2, type1)) {
1471
1467
fn (ConversionRestrictionKind::ValueToOptional);
1472
1468
}
1473
1469
}
0 commit comments