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-13637] Poor error message for closure capture list without in #56073

Open
jtbandes opened this issue Sep 30, 2020 · 3 comments
Open

[SR-13637] Poor error message for closure capture list without in #56073

jtbandes opened this issue Sep 30, 2020 · 3 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 type checker Area → compiler: Semantic analysis

Comments

@jtbandes
Copy link
Collaborator

Previous ID SR-13637
Radar rdar://problem/69845949
Original Reporter @jtbandes
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: a7baa9f1e36886e6c5cd226d988269e2

relates to:

  • SR-7774 Better Error Message for Closures Capturing Self

Issue Description:

When using [unowned self] but forgetting to add in, Swift says "Cannot find 'unowned' in scope" and suggests adding a comma. Ideally, the compiler would realize that the capture list is otherwise valid and suggest adding in instead.

See also: SR-7774

https://swift.godbolt.org/z/YEM49e

class X {
    func foo() {
        // error: cannot find 'unowned' in scope
        // error: expected ',' separator
        let fn: () -> Int = { [unowned self] 42 }
        //                     ^~~~~~~
        //                             ^
        //                            ,
    }
}
@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by Karthik (JIRA)

theindigamer (JIRA User) this is caused due to below code, where the parser ignores capture list parsing, if `in` keyword is missing. Hence capture list is treated as closure body.

As we have handled missing `in` keyword other places can we remove this check?

https://github.com/apple/swift/blob/main/lib/Parse/ParseExpr.cpp#L2523

@typesanitizer
Copy link

In the abstract, that sounds reasonable. But I'm not very familiar with that code, so I don't know if that's the right fix or if there should be a more targeted fix. You could try it out; please tag @rintaro for review if you submit a PR.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants