Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9753

REGRESSION: Ambiguity involving overloads and generics constrained by Error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Won't Do
    • Component/s: Compiler
    • Labels:
    • Environment:

      Apple Swift version 5.0 (swiftlang-1001.0.45.7 clang-1001.0.37.7)
      Target: x86_64-apple-darwin18.2.0
      ABI version: 0.6

      Description

      I have a generic struct that declares a method, and an extension to this struct that overloads the method in the case where the generic parameter conforms to Error. This has worked fine so far, but the Swift 5 compiler rejects this as an ambiguity error. It seems to be special-casing Error somehow because this doesn't happen with other protocols. This compiler error happens even in Swift 4 mode (though I don't believe it should happen in Swift 5 mode either).

      This error means Xcode 10.2 cannot compile https://github.com/lilyball/Tomorrowland.

      struct Foo<E> {
          func bar(with: Foo<E>) {}
      }
      extension Foo where E: Error {
          func bar(with: Foo<Error>) {}
      }
      let foo = Foo<Error>()
      foo.bar(with: Foo<Error>())
      

      This yields

      unnamed.swift:10:1: error: ambiguous use of 'bar(with:)'
      foo.bar(with: Foo<Error>())
      ^
      unnamed.swift:2:10: note: found this candidate
          func bar(with: Foo<E>) {}
               ^
      unnamed.swift:6:10: note: found this candidate
          func bar(with: Foo<Error>) {}
               ^
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Eridius Lily Ballard
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: