Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix <rdar://23036383> QoI: Invalid trailing closures in stmt-conditio…
…ns produce lowsy diagnostics It is a common problem that people use a call to a function with a trailing closure in a if condition, foreach loop, etc. These don't allow trailing closures, because they are ambiguous with the brace-enclosed body of the conditional statement. In an effort to improve QoI on this, perform lookahead to disambiguate the most common form of this, in a very narrow situation. This allows us to produce a nice error with fixit hints like: t.swift:26:25: error: trailing closure requires parentheses for disambiguation in this context for _ in numbers.filter {$0 > 4} { ^ instead of spewing out this garbage: t.swift:26:26: error: anonymous closure argument not contained in a closure for _ in numbers.filter {$0 > 4} { ^ t.swift:26:33: error: consecutive statements on a line must be separated by ';' for _ in numbers.filter {$0 > 4} { ^ ; t.swift:26:34: error: statement cannot begin with a closure expression for _ in numbers.filter {$0 > 4} { ^ t.swift:26:34: note: explicitly discard the result of the closure by assigning to '_' for _ in numbers.filter {$0 > 4} { ^ _ = t.swift:26:34: error: braced block of statements is an unused closure for _ in numbers.filter {$0 > 4} { ^ t.swift:26:18: error: type '(@NoEscape (Int) throws -> Bool) throws -> [Int]' does not conform to protocol 'Sequence' for _ in numbers.filter {$0 > 4} { ^ t.swift:26:34: error: expression resolves to an unused function for _ in numbers.filter {$0 > 4} { ^
- Loading branch information