Skip to content

Commit ede9302

Browse files
committed
[Sema] Fix spurious trailing closure warning
With the argument list refactoring, it's no longer sufficient to stop walking when we encounter an explicit tuple or paren. Add an additional check to stop walking when we encounter an explicit argument list. rdar://85343171
1 parent 83de1da commit ede9302

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)