Skip to content

Commit 2d6a38b

Browse files
committed
[CS] Call checkParameterList for single-expr closures
Previously we would only call this in the delayed application logic, which is currently run for multi-statement closures. I'm planning on removing that code path, which uncovered this issue.
1 parent 380f319 commit 2d6a38b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8996,9 +8996,11 @@ namespace {
89968996

89978997
switch (result) {
89988998
case SolutionApplicationToFunctionResult::Success: {
8999-
if (auto closure = dyn_cast_or_null<ClosureExpr>(
9000-
fn.getAbstractClosureExpr()))
8999+
if (auto closure =
9000+
dyn_cast_or_null<ClosureExpr>(fn.getAbstractClosureExpr())) {
90019001
TypeChecker::checkClosureAttributes(closure);
9002+
TypeChecker::checkParameterList(closure->getParameters(), closure);
9003+
}
90029004
return false;
90039005
}
90049006

test/attr/closures.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ func testNonacceptedClosures() {
1212

1313
_ = fn
1414
_ = fn2
15+
16+
// https://github.com/swiftlang/swift/issues/76291
17+
_ = { (@objc x: Int) in 0 } // expected-error {{'@objc' attribute cannot be applied to this declaration}}
18+
_ = { (@objc x: Int) in } // expected-error {{'@objc' attribute cannot be applied to this declaration}}
19+
20+
_ = { (@objc x: Int) in // expected-error {{'@objc' attribute cannot be applied to this declaration}}
21+
print("hello")
22+
return x
23+
}
1524
}

0 commit comments

Comments
 (0)