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-1557] Unused function-typed return values result in a hard error #44166

Open
swift-ci opened this issue May 18, 2016 · 5 comments
Open

[SR-1557] Unused function-typed return values result in a hard error #44166

swift-ci opened this issue May 18, 2016 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1557
Radar None
Original Reporter H2CO3 (JIRA User)
Type Bug
Environment

OS X 10.10.5, swiftc version 2.1 (swiftlang-700.1.101.6 clang-700.1.76)

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

md5: f02d43f7c7b9cce2527f9568acf6ac13

Issue Description:

If a function returns a function, and the return value of the former is unused, a compilation error occurs:

    public func foo(x: Int) -> () -> Int {
        return { x }
    }

    foo(42) // ignored return value errors out: "expression resolves to an unused function"

For consistency (and convenience of testing, where I found this problem), such unused return values should yield a warning only.

@belkadan
Copy link
Contributor

For anyone coming across this, you can silence the error the same way as the usual warning: assign to _.

@jtbandes
Copy link
Collaborator

Is turning this into a warning really the right way to go? If so, should all unused-function expressions just be warnings?

Perhaps expression_unused_function should be entirely removed in favor of expression_unused_result?

@swift-ci
Copy link
Collaborator Author

Comment by Árpád Goretity (JIRA)

@jtbandes I don't think this should be a special case at all. Why should unused closure return values cause an error while everything else only results in a warning? It's just expressions, after all.

In my opinion, unused non-return-value expressions of closure type (e.g. global functions) should emit the "unused function" warning (still not an error), and every dead return value should, regardless to its type, emit an "unused result" warning. So, expression_unused_function seems useful in general, it's just misused in this particular case. From what I can tell, the problem arises because TypeChecker::checkIgnoredExpr() only looks at the type of unused expressions, and in the case of functions, it doesn't check whether the expression is a return value or something else.

@swift-ci
Copy link
Collaborator Author

Comment by Step Christopher (JIRA)

I have a patch in progress on this (collaborated with markd2 (JIRA User)). Changed to warning, tests updated. Running into a validation test failure that I'd like to poke at more before putting up a WIP PR.

@belkadan
Copy link
Contributor

Resetting assignee on all Starter Bugs not modified since 2018.

@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 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants