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-4318] Useless diagnostic with type not conforming to Equatable #46901

Closed
NachoSoto opened this issue Mar 22, 2017 · 9 comments
Closed

[SR-4318] Useless diagnostic with type not conforming to Equatable #46901

NachoSoto opened this issue Mar 22, 2017 · 9 comments
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

@NachoSoto
Copy link
Contributor

Previous ID SR-4318
Radar None
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment
  • Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)

  • Swift version 3.1 (swiftlang-802.0.48 clang-802.0.48)

  • Swift version 4.0 (swiftlang-900.0.59 clang-900.0.34.2)

  • Swift version 4.1 (swiftlang-902.0.34 clang-902.0.30)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 4231b4a94173b29ece8dca6219bf66e9

Issue Description:

protocol P {}
struct S: P {
    static func == (lhs: S, rhs: S) -> Bool { return true } 
}
func f<T: P>(_ a: T, _ b: (T, T) -> Bool) {}

func g<T: P>(_ a: T) {
    f(a, ==)
}

g(S())

Error:

error: repl.swift:8:10: error: ambiguous reference to member '=='
    f(a, ==)
         ^~

repl.swift:3:17: note: found this candidate
    static func == (lhs: S, rhs: S) -> Bool { return true }
                ^

In my project (with a not-reduced version of this) I actually get, quite literally, a lot of ambiguous references... (see screenshot)

@belkadan
Copy link
Contributor

There's no direct connection between == and Equatable, which makes it hard to do better here in a completely generic way. But this may be a common enough case to be worth special-casing.

@belkadan
Copy link
Contributor

I guess there is a connection if one of the candidates we find is in a protocol. Then we can suggest conforming to that protocol.

Swift.Equatable:149:24: note: found this candidate
    public static func ==(lhs: Self, rhs: Self) -> Bool
                       ^

But that wouldn't help for something like !=.

@jckarter
Copy link
Member

jckarter commented Apr 4, 2017

There'd at least hopefully be fewer != overloads in the wild (and even fewer once conditional conformances work).

@jckarter
Copy link
Member

jckarter commented Apr 4, 2017

The "connection if one of the candidates is in a protocol" sounds a lot like Doug's vague plan to optimize operator resolution by folding together candidates that look like a protocol conformance. I think the way we present this error is also pretty atrocious—I know it's all crammed in one note to work around Xcode's lack of good cross-file note support, but that's something that Xcode ought to fix. It'd still be somewhat more manageable to have one note per candidate.

@NachoSoto
Copy link
Contributor Author

FYI Swift 3.1 produces the same result.

@NachoSoto
Copy link
Contributor Author

I just filed SR-4795 with a similar problem.

@NachoSoto
Copy link
Contributor Author

Still an issue in Swift 4.0

@NachoSoto
Copy link
Contributor Author

Still an issue in Swift 4.1

@slavapestov
Copy link
Member

#18831 (comment)

@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

4 participants