[SR-7503] guard statement parsing is confused by embedded trailing closure arguments #50045
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
Attachment: Download
Environment
$ swift --version
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
Additional Detail from JIRA
md5: 5e40d48e7f76ac80f9c5d6b347cfe962
Issue Description:
You cannot mix a `guard let …` statement with the trailing closure utilisation (or whatever "doFoo { … }" is called vs "doFoo({ … })") - the `swift` compiler gets mightily confused and emits multiple error messages, not a single one of which is actually appropriate in the circumstances, nor any of which convey what the problem is precisely (that it's assuming any '{' not in an embedded scope within the guard expression must be preceded by 'else').
See the attached Xcode playground for demonstration code.
You can of course work around this error by not utilising the trailing closure convenience syntax. It's a very nice convenience, though, so it's a shame to not be able to use it. 🙂
The text was updated successfully, but these errors were encountered: