Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7503] guard statement parsing is confused by embedded trailing closure arguments #50045

Open
swift-ci opened this issue Apr 23, 2018 · 5 comments
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7503
Radar rdar://problem/39748416
Original Reporter wadetregaskis (JIRA User)
Type Bug

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
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee None
Priority Medium

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. 🙂

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Apr 26, 2018

Swift Sync System create

@belkadan
Copy link
Contributor

belkadan commented May 1, 2018

It's supposed to give you good error messages, but yes, it's not a supported syntax, for consistency with if and while.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 3, 2018

Comment by Wade Tregaskis (JIRA)

Does it need to be consistent?

Another way to disambiguate if and while cases would be to have an optional 'then' or 'do' or similar keyword to insert.

@belkadan
Copy link
Contributor

belkadan commented May 3, 2018

Any change there would have to go through the Swift Evolution Process.

@swift-ci
Copy link
Collaborator Author

Comment by Steffan Andrews (JIRA)

This recently threw me. Further confusion is that just a let statement compiles fine but adding guard to it breaks the compiler. That kind of inconsistency seems very un-Swifty.

See my recent quandary here: https://forums.swift.org/t/guard-let-throws-warnings-but-let-does-not-swift-5-2

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants