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-7666] Compiler incorrectly infers generic parameter type of methods used within conditionally conformed extensions for that type #50206

Open
swift-ci opened this issue May 11, 2018 · 2 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-7666
Radar None
Original Reporter twof (JIRA User)
Type Bug
Environment

Xcode 9.3

Swift 4.1

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

md5: c60aeddf4f8e8176364c406e519dc787

relates to:

  • SR-11137 Type inference compiler error

Issue Description:

Reproduction code:

 extension Set where Element == Int \{

    func foo() \{

        let arr: [String] = ["hello", "world"]

        let stringSet = Set(arr) // Error: Type of expression is ambiguous without more context

    }

 

    func bar() \{

        let arr: [String] = ["hello", "world"]

        let stringSet: Set<String> = Set.init(arr) // Error: No Set<Int>.Type.init canidates produce the expected contextual result type Set<String>

    }

 

    func baz() \{

        let arr: [String] = ["hello", "world"]

        let stringSet = Set<String>(arr) // No error

    }

}
@belkadan
Copy link
Contributor

@DougGregor, you have a dup for this, right?

Alex, the rule (which I think we regret now) is that within a type context the unadorned name of the type refers to the current Self type, rather than a generic type with inferred parameters. You'll have to explicitly say Set<String>(arr) here.

@swift-ci
Copy link
Collaborator Author

Comment by Alex Reilly (JIRA)

Ahhh I see. Interesting! Thanks for the response.

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

No branches or pull requests

2 participants