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

Regression in overload resolution

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: None
    • Labels:
      None

      Description

      Previous versions of the compiler have been able to correctly disambiguate between the following two overloads:

      public func expect<T>(_ expression: @autoclosure @escaping () throws -> T?, file: StaticString = "a", line: UInt = 1) -> T {
        print("First")
        return try! expression()!
      }
      
      /// Make an expectation on a given actual value. The closure is lazily invoked.
      public func expect<T>(_ file: StaticString = "b", line: UInt = 2, expression: @escaping () throws -> T?) -> T {
        print("Second")
        return try! expression()!
      }
      
      print("Hello world!")
      let x = expect { 1 }
      print("x: \(x)")
      let y = expect(2)
      print("y: \(y)")
      

      But a recent version of the compiler built from master does not.

      Expected:

      Hello world!
      Second
      x: 1
      First
      y: 2
      

       

      Actual:

      experimental/users/saeta/foo/foo.swift:14:9: error: ambiguous use of 'expect'
      let x = expect { 1 }
              ^
      experimental/users/saeta/foo/foo.swift:2:13: note: found this candidate
      public func expect<T>(_ expression: @autoclosure @escaping () throws -> T?, file: StaticString = "a", line: UInt = 1) -> T {
                  ^
      experimental/users/saeta/foo/foo.swift:8:13: note: found this candidate
      public func expect<T>(_ file: StaticString = "b", line: UInt = 2, expression: @escaping () throws -> T?) -> T {
                  ^
      

      Couple extra notes: if I remove the generic parameter, then it can resolve the ambiguity. Additionally, the regression appears to have been introduced somewhere between 81a65e143598e8df7f96469121406cc410fafe71 and aef19c95260c120938298b0ffbc492e4edb82bfb.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              saeta Brennan Saeta
              Reporter:
              saeta Brennan Saeta
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: