Skip to content

Commit 5a498db

Browse files
committed
[TypeChecker] Fix a problem with rethrows classification.
We failed to properly classify arguments that are of optional function type, in this case leading to a verification failure due to the throws attribute on the apply expression not being set to some value. Fixes: SR-9102 / rdar://problem/45615204
1 parent 1ed46b4 commit 5a498db

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/Sema/TypeCheckError.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,10 @@ class ApplyClassifier {
713713

714714
// If it doesn't have function type, we must have invalid code.
715715
Type argType = fn.getType();
716-
auto argFnType = (argType ? argType->getAs<AnyFunctionType>() : nullptr);
716+
if (!argType) return Classification::forInvalidCode();
717+
718+
auto argFnType =
719+
argType->lookThroughAllOptionalTypes()->getAs<AnyFunctionType>();
717720
if (!argFnType) return Classification::forInvalidCode();
718721

719722
// If it doesn't throw, this argument does not cause the call to throw.

test/Constraints/sr9102.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
func test(_ a: [Int], _ f: ((Int) -> Bool)?) {
4+
_ = a.filter(f!)
5+
}

0 commit comments

Comments
 (0)