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-12459] Cannot call equality operator declared as a static member of a protocol #54899

Closed
ahoppen opened this issue Mar 31, 2020 · 5 comments
Assignees
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

@ahoppen
Copy link
Contributor

ahoppen commented Mar 31, 2020

Previous ID SR-12459
Radar rdar://problem/62202443
Original Reporter @ahoppen
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @ahoppen
Priority Medium

md5: 886bc3d5b61b666595f45872e20f5f63

Issue Description:

Take a look at the following code:

protocol Foo {}


extension Foo {
  static func ==(lhs: Foo, rhs: Foo) -> Bool {
    fatalError()
  }
}


struct Bar: Foo {}

let a: Foo = Bar()
let b: Foo = Bar()
print(a == b) // Error: Binary operator '==' cannot be applied to two 'Foo' operands

I would expect a == b to call the == operator declared in the extension of Foo. However, I get an error „Binary operator '==' cannot be applied to two 'Foo' operands“.

Using Swift 5.2 shipped with Xcode 11.4 (11E146, swiftlang-1103.0.32.1)

@hamishknight
Copy link
Collaborator

The problem is that there's no way to infer the type for the implicit Self parameter, we should probably emit a warning explaining this to the user and suggest making it a top-level operator function instead.

@ahoppen
Copy link
Contributor Author

ahoppen commented Apr 3, 2020

A warning sounds like a good solution to me if it's not easy to get it to work 👍

@beccadax
Copy link
Contributor

@swift-ci create

@theblixguy
Copy link
Collaborator

On master, the diagnostic now says:

/Users/spare/Desktop/test.swift:15:9: error: generic parameter 'Self' could not be inferred
print(a == b)
        ^

@xedin
Copy link
Member

xedin commented Mar 30, 2021

I think diagnostic about `generic parameter 'Self' could not be inferred` makes sense here.

@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

5 participants