@@ -1675,31 +1675,6 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
1675
1675
choice.getFunctionRefKind (), locator);
1676
1676
}
1677
1677
1678
- if (!isRequirementOrWitness (locator) &&
1679
- choice.getDecl ()->getAttrs ().hasAttribute <OptionalAttr>() &&
1680
- !isa<SubscriptDecl>(choice.getDecl ())) {
1681
- // For a non-subscript declaration that is an optional
1682
- // requirement in a protocol, strip off the lvalue-ness (FIXME:
1683
- // one cannot assign to such declarations for now) and make a
1684
- // reference to that declaration be optional.
1685
- //
1686
- // Subscript declarations are handled within
1687
- // getTypeOfMemberReference(); their result types are optional.
1688
-
1689
- // Deal with values declared as implicitly unwrapped, or
1690
- // functions with return types that are implicitly unwrapped.
1691
- if (choice.isImplicitlyUnwrappedValueOrReturnValue ()) {
1692
- // Build the disjunction to attempt binding both T? and T (or
1693
- // function returning T? and function returning T).
1694
- Type ty = createTypeVariable (locator);
1695
- buildDisjunctionForImplicitlyUnwrappedOptional (ty, refType,
1696
- locator);
1697
- addConstraint (ConstraintKind::Bind, boundType,
1698
- OptionalType::get (ty->getRValueType ()), locator);
1699
- bindConstraintCreated = true ;
1700
- }
1701
- refType = OptionalType::get (refType->getRValueType ());
1702
- }
1703
1678
// For a non-subscript declaration found via dynamic lookup, strip
1704
1679
// off the lvalue-ness (FIXME: as a temporary hack. We eventually
1705
1680
// want this to work) and make a reference to that declaration be
@@ -1708,7 +1683,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
1708
1683
// Subscript declarations are handled within
1709
1684
// getTypeOfMemberReference(); their result types are unchecked
1710
1685
// optional.
1711
- else if (isDynamicResult) {
1686
+ if (isDynamicResult) {
1712
1687
if (isa<SubscriptDecl>(choice.getDecl ())) {
1713
1688
// We always expect function type for subscripts.
1714
1689
auto fnTy = refType->castTo <AnyFunctionType>();
@@ -1773,8 +1748,31 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
1773
1748
}
1774
1749
1775
1750
bindConstraintCreated = true ;
1776
- }
1751
+ } else if (!isRequirementOrWitness (locator) &&
1752
+ choice.getDecl ()->getAttrs ().hasAttribute <OptionalAttr>() &&
1753
+ !isa<SubscriptDecl>(choice.getDecl ())) {
1754
+ // For a non-subscript declaration that is an optional
1755
+ // requirement in a protocol, strip off the lvalue-ness (FIXME:
1756
+ // one cannot assign to such declarations for now) and make a
1757
+ // reference to that declaration be optional.
1758
+ //
1759
+ // Subscript declarations are handled within
1760
+ // getTypeOfMemberReference(); their result types are optional.
1761
+
1762
+ // Deal with values declared as implicitly unwrapped, or
1763
+ // functions with return types that are implicitly unwrapped.
1764
+ if (choice.isImplicitlyUnwrappedValueOrReturnValue ()) {
1765
+ // Build the disjunction to attempt binding both T? and T (or
1766
+ // function returning T? and function returning T).
1767
+ Type ty = createTypeVariable (locator);
1768
+ buildDisjunctionForImplicitlyUnwrappedOptional (ty, refType, locator);
1769
+ addConstraint (ConstraintKind::Bind, boundType,
1770
+ OptionalType::get (ty->getRValueType ()), locator);
1771
+ bindConstraintCreated = true ;
1772
+ }
1777
1773
1774
+ refType = OptionalType::get (refType->getRValueType ());
1775
+ }
1778
1776
// If the declaration is unavailable, note that in the score.
1779
1777
if (choice.getDecl ()->getAttrs ().isUnavailable (getASTContext ())) {
1780
1778
increaseScore (SK_Unavailable);
0 commit comments