|
29 | 29 | #include "swift/AST/ProtocolConformance.h" |
30 | 30 | #include "swift/AST/TypeTransform.h" |
31 | 31 | #include "swift/Sema/ConstraintSystem.h" |
| 32 | +#include "swift/Sema/PreparedOverload.h" |
32 | 33 | #include "swift/Basic/Assertions.h" |
33 | 34 | #include "swift/Basic/Statistic.h" |
| 35 | +#include "swift/Basic/Defer.h" |
34 | 36 |
|
35 | 37 | using namespace swift; |
36 | 38 | using namespace constraints; |
@@ -932,7 +934,20 @@ DeclReferenceType |
932 | 934 | ConstraintSystem::getTypeOfReference(ValueDecl *value, |
933 | 935 | FunctionRefInfo functionRefInfo, |
934 | 936 | ConstraintLocatorBuilder locator, |
935 | | - DeclContext *useDC) { |
| 937 | + DeclContext *useDC, |
| 938 | + PreparedOverload *preparedOverload) { |
| 939 | + if (preparedOverload) { |
| 940 | + ASSERT(!PreparingOverload); |
| 941 | + PreparingOverload = true; |
| 942 | + } |
| 943 | + |
| 944 | + SWIFT_DEFER { |
| 945 | + if (preparedOverload) { |
| 946 | + ASSERT(PreparingOverload); |
| 947 | + PreparingOverload = false; |
| 948 | + } |
| 949 | + }; |
| 950 | + |
936 | 951 | if (value->getDeclContext()->isTypeContext() && isa<FuncDecl>(value)) { |
937 | 952 | // Unqualified lookup can find operator names within nominal types. |
938 | 953 | auto func = cast<FuncDecl>(value); |
@@ -1507,13 +1522,15 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType( |
1507 | 1522 | DeclReferenceType ConstraintSystem::getTypeOfMemberReference( |
1508 | 1523 | Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup, |
1509 | 1524 | FunctionRefInfo functionRefInfo, ConstraintLocator *locator, |
1510 | | - SmallVectorImpl<OpenedType> *replacementsPtr) { |
| 1525 | + SmallVectorImpl<OpenedType> *replacementsPtr, |
| 1526 | + PreparedOverload *preparedOverload) { |
1511 | 1527 | // Figure out the instance type used for the base. |
1512 | 1528 | Type resolvedBaseTy = getFixedTypeRecursive(baseTy, /*wantRValue=*/true); |
1513 | 1529 |
|
1514 | 1530 | // If the base is a module type, just use the type of the decl. |
1515 | 1531 | if (resolvedBaseTy->is<ModuleType>()) { |
1516 | | - return getTypeOfReference(value, functionRefInfo, locator, useDC); |
| 1532 | + return getTypeOfReference(value, functionRefInfo, locator, useDC, |
| 1533 | + preparedOverload); |
1517 | 1534 | } |
1518 | 1535 |
|
1519 | 1536 | // Check to see if the self parameter is applied, in which case we'll want to |
@@ -2427,10 +2444,12 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator, |
2427 | 2444 | declRefType = getTypeOfMemberReference( |
2428 | 2445 | baseTy, choice.getDecl(), useDC, |
2429 | 2446 | (kind == OverloadChoiceKind::DeclViaDynamic), |
2430 | | - choice.getFunctionRefInfo(), locator, nullptr); |
| 2447 | + choice.getFunctionRefInfo(), locator, nullptr, |
| 2448 | + /*preparedOverload=*/nullptr); |
2431 | 2449 | } else { |
2432 | 2450 | declRefType = getTypeOfReference( |
2433 | | - choice.getDecl(), choice.getFunctionRefInfo(), locator, useDC); |
| 2451 | + choice.getDecl(), choice.getFunctionRefInfo(), locator, useDC, |
| 2452 | + /*preparedOverload=*/nullptr); |
2434 | 2453 | } |
2435 | 2454 |
|
2436 | 2455 | openedType = declRefType.openedType; |
|
0 commit comments