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-5983] Unused result warning phrasing is worse for closures than normal functions #48542

Closed
huonw mannequin opened this issue Sep 26, 2017 · 5 comments
Closed

[SR-5983] Unused result warning phrasing is worse for closures than normal functions #48542

huonw mannequin opened this issue Sep 26, 2017 · 5 comments
Assignees
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 good first issue Good for newcomers

Comments

@huonw
Copy link
Mannequin

huonw mannequin commented Sep 26, 2017

Previous ID SR-5983
Radar rdar://problem/26661027
Original Reporter @huonw
Type Bug
Status Resolved
Resolution Done
Environment

Swift 4.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee @AnthonyLatsis
Priority Medium

md5: 9af0fbe9cbc462085d6aaa484bf3d040

Issue Description:

func foo() -> Int { return 0 }
foo()

let f: () -> Int = foo
f()

func bar(g: () -> Int) { g() }

Gives:

rdar26661027.swift:2:1: warning: result of call to 'foo()' is unused
foo()
^  ~~
rdar26661027.swift:5:1: warning: result of call is unused, but produces 'Int'
f()
^~~
rdar26661027.swift:8:26: warning: result of call is unused, but produces 'Int'
func bar(g: () -> Int) { g() }
                         ^~~

The "but produces ..." addition is a bit awkward. This typing information doesn't seem particularly important, although maybe for closures it is harder to work out what the type actually is?

In any case, maybe the message for the expression_unused_result_unknown WARNING in include/swift/AST/DiagnosticsSema.def could be wordsmithed a bit, e.g. result of call to function returning '%0' is unused.

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 4, 2017

Comment by Rahul Ranjan (JIRA)

Hi @huonw ,

I am interested in solving this bug. I am new to Swift community and so can please guide me for initial steps to resolve this issue. I have already setup the dev environment but don't know where to look.

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 4, 2017

Comment by Rahul Ranjan (JIRA)

I have created the pull request. #12266

@AnthonyLatsis
Copy link
Collaborator

Which one do you consider the most natural?

  • result of call to function returning T is unused

  • result of call producing T is unused

  • result of call returning T is unused

@AnthonyLatsis
Copy link
Collaborator

PR for master #16059

@AnthonyLatsis
Copy link
Collaborator

The diagnostic text has been updated to
{{result of call to {function|closure} returning 'T' is unused}}
For calls that are applied to names, i.e. {{name()}}, it uses function;
For calls that are applied to anonymous blocks, i.e. {{{...}()}}, it uses {{closure}}.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants