Skip to content

Commit 60f7d20

Browse files
committed
[Effects checking] Handle optional function types for dynamic @objc calls
We've been missing this case forever, but it hadn't come up until we performed "unsafe" checking on calls.
1 parent 81b68e5 commit 60f7d20

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,18 @@ class AbstractFunction {
385385

386386
Type getType() const {
387387
switch (getKind()) {
388-
case Kind::Opaque: return getOpaqueFunction()->getType();
388+
case Kind::Opaque:
389+
return getOpaqueFunction()->getType()->lookThroughSingleOptionalType();
389390
case Kind::Function: {
390391
auto *AFD = getFunction();
391392
if (AFD->hasImplicitSelfDecl() && AppliedSelf)
392393
return AFD->getMethodInterfaceType();
393394
return AFD->getInterfaceType();
394395
}
395396
case Kind::Closure: return getClosure()->getType();
396-
case Kind::Parameter: return getParameter()->getInterfaceType();
397+
case Kind::Parameter:
398+
return getParameter()->getInterfaceType()
399+
->lookThroughSingleOptionalType();
397400
}
398401
llvm_unreachable("bad kind");
399402
}
@@ -1827,6 +1830,11 @@ class ApplyClassifier {
18271830
return;
18281831
}
18291832

1833+
// Can end up with an optional type when dynamically dispatching to
1834+
// @objc.
1835+
if (auto optFnType = fnInterfaceType->getOptionalObjectType())
1836+
fnInterfaceType = optFnType;
1837+
18301838
// Use the most significant result from the arguments.
18311839
FunctionType *fnSubstType = nullptr;
18321840
if (auto *fnGenericType = fnInterfaceType->getAs<GenericFunctionType>())

0 commit comments

Comments
 (0)