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-1648] Fail to infer type on closure computed property #44257

Closed
swift-ci opened this issue May 31, 2016 · 3 comments
Closed

[SR-1648] Fail to infer type on closure computed property #44257

swift-ci opened this issue May 31, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1648
Radar None
Original Reporter lingol (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 6acd7cb4eab890acede87fb94da6cb28

duplicates:

  • SR-1570 'Generic parameter 'Result' could not be inferred' compiler error for wrapper functions like autoreleasepool that return the result of their closure argument.

Issue Description:

Show the code:

class Phone {
    // numbers inferred as [Int], works fine
    var numbers = { [0, 1, 2] }()

    // compiler complains of type inferring
    // unless the type is specified: var table : [Int] = { ...
    var table = {
        var dummy = 0
        return [0, 1, 2]
    }()
}
@belkadan
Copy link
Contributor

This is correct behavior: Swift does not infer parameter or return types from the bodies of multi-statement closures.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 1, 2016

Comment by Ling Guo (JIRA)

Following the links, I can see it's a trade-off decision.
Yet developers keep complaining about multi-statement closure return type inferring, will there be any chance supporting it in the future?

@belkadan
Copy link
Contributor

belkadan commented Jun 1, 2016

I won't say it's never going to happen, but it's a pretty big redesign, and I don't think it's the thing to focus on when we already have strong and non-trivial goals for Swift 3 and Swift 4.

@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
Projects
None yet
Development

No branches or pull requests

2 participants