Skip to content

Commit 283cb60

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 9220e68 commit 283cb60

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
@@ -1838,6 +1838,8 @@ class ApplyClassifier {
18381838
FunctionType *fnSubstType = nullptr;
18391839
if (auto *fnGenericType = fnInterfaceType->getAs<GenericFunctionType>())
18401840
fnSubstType = fnGenericType->substGenericArgs(fnRef.getSubstitutions());
1841+
else if (fnRef.getSubstitutions())
1842+
fnSubstType = fnInterfaceType.subst(fnRef.getSubstitutions())->getAs<FunctionType>();
18411843
else
18421844
fnSubstType = fnInterfaceType->getAs<FunctionType>();
18431845

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)