Skip to content

[SR-12459] Cannot call equality operator declared as a static member of a protocol #54899

@ahoppen

Description

@ahoppen
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)

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationtype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions