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-6607] Incorrect ambiguous reference with constrained protocol extension #49157

Closed
swift-ci opened this issue Dec 13, 2017 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6607
Radar rdar://problem/36060088
Original Reporter mergesort (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee mergesort (JIRA)
Priority Medium

md5: a378bee46a951e772c9450824248708b

Issue Description:

Hi there, long time Swifter, first time poster. I couldn't find a bug matching this when I searched, but feel free to correct me if any of this wrong. 🙂

I believe this is a bug in Swift, resulting in an error `Ambiguous reference to member` when the two functions in constrained extensions (one protocol and one concrete) don't have the same overload.

I've attached a playground with a reproducible example.

Thanks a lot!

@belkadan
Copy link
Contributor

Thanks for filing! In this case, the problem is that neither function applies; an array of Foo values isn't the same as an array of concrete types that conform to Foo. But the diagnostic should be able to tell which function you're trying to call from (a) the name, and (b) the fact that this is a really common mismatch (protocol value vs. type constrained by protocol), and the diagnostic should explain it.

@xedin, you have a dup for this already, right?

@xedin
Copy link
Member

xedin commented Dec 14, 2017

I think I do, but I can't find it. Will duplicate later.

@xedin
Copy link
Member

xedin commented Dec 14, 2017

@swift-ci create

@xedin
Copy link
Member

xedin commented Sep 10, 2021

Diagnostic for this problem has been improved in Xcode 13:

error: protocol 'Foo' as a type cannot conform to the protocol itself
text.find(some: "test")
^
note: only concrete types such as structs, enums and classes can conform to protocols
text.find(some: "test")
^
note: required by referencing instance method 'find(some:)' on 'Array' where 'Element' = 'Foo'
extension Array where Element: Foo {
^

Please use either Xcode 13 beta or main branch snapshot to verify and close.

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants