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-14340] Compiler should suggest optional chaining when trying to call optional closure #56699

Closed
swift-ci opened this issue Mar 11, 2021 · 1 comment · Fixed by #60321
Closed
Assignees
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14340
Radar rdar://problem/75364845
Original Reporter cukier (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 76f3c7f5dfc3f0e5a6c3673c142b65e4

Issue Description:

let test: (() -> Void)?
test() 

Today, this code generates two fixits:

note: coalesce using '??' to provide a default when the optional value contains 'nil'
test()
^
(    ?? <#default value#>)
note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
test()
^
    !

It would be nice if it suggested optional chaining, just like for accessing properties, because not everyone may be aware that you can write `test?()`

note: chain the optional using '?' to call only for non-'nil' base values
test()
^
    ?
@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@theblixguy theblixguy self-assigned this Jul 30, 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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants