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-14838] Bare closures in top-level code don't get the 'do' fix-it #57185

Open
beccadax opened this issue Jun 28, 2021 · 0 comments
Open

[SR-14838] Bare closures in top-level code don't get the 'do' fix-it #57185

beccadax opened this issue Jun 28, 2021 · 0 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement parser Area → compiler: The legacy C++ parser

Comments

@beccadax
Copy link
Contributor

Previous ID SR-14838
Radar None
Original Reporter @beccadax
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, Parser
Assignee None
Priority Medium

md5: 80a769776aad254b1527dcf52d3526fa

Issue Description:

If you write a bare closure as a statement in a function, we suggest using do instead:

  3> func fn() { { 42 } }
error: repl.swift:3:13: error: closure expression is unused
func fn() { { 42 } }
            ^

repl.swift:3:13: note: did you mean to use a 'do' statement?
func fn() { { 42 } }
            ^
            do 

But we don't have that for top-level code, apparently because it's diagnosed during parsing instead of type checking:

  3> { 42 }
error: repl.swift:3:1: error: top-level statement cannot begin with a closure expression
{ 42 }
^

We should either let the type checker catch this error in top-level code too, or we should emit the same fix-it here.

@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
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

1 participant