Skip to content

Commit d835783

Browse files
authored
Merge pull request #40266 from hamishknight/hoping-for-closure
2 parents 2a9c148 + ede9302 commit d835783

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,13 @@ static void checkStmtConditionTrailingClosure(ASTContext &ctx, const Expr *E) {
35093509

35103510
bool shouldWalkIntoTapExpression() override { return false; }
35113511

3512+
std::pair<bool, ArgumentList *>
3513+
walkToArgumentListPre(ArgumentList *args) override {
3514+
// Don't walk into an explicit argument list, as trailing closures that
3515+
// appear in child arguments are fine.
3516+
return {args->isImplicit(), args};
3517+
}
3518+
35123519
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
35133520
switch (E->getKind()) {
35143521
case ExprKind::Paren:

test/expr/closure/trailing.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,12 @@ class TrailingDerived : TrailingBase {
466466
super.init(x: x) {}
467467
}
468468
}
469+
470+
// rdar://85343171 - Spurious warning on trailing closure in argument list.
471+
func rdar85343171() {
472+
func foo(_ i: Int) -> Bool { true }
473+
func bar(_ fn: () -> Void) -> Int { 0 }
474+
475+
// Okay, as trailing closure is nested in argument list.
476+
if foo(bar {}) {}
477+
}

0 commit comments

Comments
 (0)