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-11472] Generic parameter inference problem #53872

Closed
jeremyabannister opened this issue Sep 14, 2019 · 1 comment
Closed

[SR-11472] Generic parameter inference problem #53872

jeremyabannister opened this issue Sep 14, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@jeremyabannister
Copy link

Previous ID SR-11472
Radar None
Original Reporter @jeremyabannister
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 3094e6c47b27e8d301bf4f2a2ef9c7e9

duplicates:

  • SR-1789 Swift can't infer types in generic methods that reuse part of the struct/class' parameters

Issue Description:

This code compiles with Swift 5:

struct A <X> {
    
    let dict: [Int: X]
    
    init (dict: [Int: X]) {
        self.dict = dict
    }
    
    func map <Y> (_ transform: (X)->Y) -> A<Y> {
        return A<Y>(dict: dict.mapValues { transform($0) })
    }
}

but this code does not:

struct A <X> {
    
    let dict: [Int: X]
    
    init (dict: [Int: X]) {
        self.dict = dict
    }
    
    func map <Y> (_ transform: (X)->Y) -> A<Y> {
        return A(dict: dict.mapValues { transform($0) })
    }
}

The only difference is that I have removed the explicit type from the construction of A in the map method. Of course the generic parameter is already specified in two ways, one is the return type and the other is the fact that the transform spits out values of type Y. What's going on here?

@belkadan
Copy link
Contributor

Yep. :-( See the discussion on SR-1789.

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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants