Skip to content

Commit e561329

Browse files
committed
[Constraint solver] Minor cleanup for @optional declarations.
1 parent 6246e7e commit e561329

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,7 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload,
15261526
// See ConstraintSystem::resolveOverload() -- optional and dynamic
15271527
// subscripts are a special case, because the optionality is
15281528
// applied to the result type and not the type of the reference.
1529-
if (subscript->getAttrs().hasAttribute<OptionalAttr>() ||
1530-
overload.getKind() == OverloadChoiceKind::DeclViaDynamic)
1529+
if (subscript->getAttrs().hasAttribute<OptionalAttr>())
15311530
elementTy = OptionalType::get(elementTy->getRValueType());
15321531

15331532
auto indices = subscript->getInterfaceType()
@@ -1559,11 +1558,14 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload,
15591558
}
15601559

15611560
type = type->castTo<FunctionType>()->getResult();
1562-
} else {
1563-
return type;
15641561
}
15651562
}
15661563

1564+
// Handle "@objc optional" for non-subscripts; subscripts are handled above.
1565+
if (decl->getAttrs().hasAttribute<OptionalAttr>() &&
1566+
!isa<SubscriptDecl>(decl))
1567+
type = OptionalType::get(type->getRValueType());
1568+
15671569
return type;
15681570
}
15691571

@@ -1821,7 +1823,7 @@ Type ConstraintSystem::findCommonOverloadType(
18211823
// If we can't even get a type for the overload, there's nothing more to
18221824
// do.
18231825
Type overloadType =
1824-
getEffectiveOverloadType(overload, /*allowMembers=*/false, /*FIXME:*/DC);
1826+
getEffectiveOverloadType(overload, /*allowMembers=*/false, /*FIXME:*/DC);
18251827
if (!overloadType) {
18261828
return true;
18271829
}

0 commit comments

Comments
 (0)