Closed
Description
Previous ID | SR-2948 |
Radar | None |
Original Reporter | Amnykon (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, StarterBug |
Assignee | None |
Priority | Medium |
md5: 021904a7cf17206d058f15ce5ed4b66f
relates to:
- SR-7297 Discarding a function from a discardableResult method causes a compiler error
Issue Description:
A function marked with @discardableResult should not throw an error if it is returning closure is unused.
The current work around is to set _ to the returning closure.
@discardableResult func run (_ closure: @escaping ()->()) -> (()->()) {
closure()
return closure
}
var closure={print(1)}
_ = run(closure)
// Prints 1
_ = run(run(closure))
// Prints 1
// Prints 1
run(closure)
// should Print 1 but errors with:
// discardableResultOfClosure.swift:14:1: error: expression resolves to an unused function
// run(closure)
// ^~~~~~~~~~~~