Skip to content

Commit 5391887

Browse files
committed
[Effects] Ensure that we properly substitute function types in ByClosure checks
We weren't substituting generic arguments into function types. In the presence of parameter packs, this could mean that the parameter and argument lists no longer match up, which would cause the effects checker to prematurely bail out after treating this as "invalid" code. The overall effect is that we would not properly check for throwing behavior in this case, allowing invalid code (as in the example) and miscompiling valid code by not treating the call as throwing. Fixes rdar://153926820.
1 parent 0e3da0e commit 5391887

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,8 @@ class ApplyClassifier {
18481848
FunctionType *fnSubstType = nullptr;
18491849
if (auto *fnGenericType = fnInterfaceType->getAs<GenericFunctionType>())
18501850
fnSubstType = fnGenericType->substGenericArgs(fnRef.getSubstitutions());
1851+
else if (fnRef.getSubstitutions())
1852+
fnSubstType = fnInterfaceType.subst(fnRef.getSubstitutions())->getAs<FunctionType>();
18511853
else
18521854
fnSubstType = fnInterfaceType->getAs<FunctionType>();
18531855

test/stmt/errors.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,17 @@ func takesClosure(_: (() -> ())) throws -> Int {}
256256
func passesClosure() {
257257
_ = try takesClosure { } // expected-error {{errors thrown from here are not handled}}
258258
}
259+
260+
// Parameter packs checking
261+
struct S {
262+
static func packTest<each T>(_ values: repeat (each T).Type, shouldThrow: Bool) throws -> Bool {
263+
if (shouldThrow) {
264+
throw MSV.Foo
265+
}
266+
return true
267+
}
268+
269+
static func test() -> Bool {
270+
return try packTest(String.self, String.self, shouldThrow: true) // expected-error{{errors thrown from here are not handled}}
271+
}
272+
}

0 commit comments

Comments
 (0)