Swift 1.2 can’t resolve overload methods based on function return

Originator:jlieske
Number:rdar://19849478 Date Originated:16-Feb-2015 12:01 PM
Status:Duplicate Resolved:
Product:Developer Tools Product Version:Xcode Version 6.3 beta 2 (6D520o)
Classification:Bug Reproducible:Always
 
I have a Result<T> type that supports monadic flow control methods.  The methods are overloaded in two versions:

* One overload takes a function that returns the monadic type: () -> Result<()>

* Other overload takes a function that returns Void: () -> ()

In Swift 1.1, this code compiled and ran correctly.  In Swift 1.2 it fails to compile.  The error message reports an ambiguous overload.

Steps to Reproduce:
1. Create Swift project in Xcode.
2. Implement Result<T> type and monadic flow control methods in Swift.
3. Implement test of Result<T> type and monadic flow control.

Expected Results:
Xcode compiles the Swift code and tests succeed. 

Actual Results:
Xcode 6.3b1 fails to compile the attached file.

The error message in Xcode 6.3b1:

/Users/jay/Coding/Swift/TrySwift/TryThenWhile/TryThenWhile.swift:137:19: error: ambiguous use of 'thenWhile'
        let rs4 = Result(s1)
                  ^
/Users/jay/Coding/Swift/TrySwift/TryThenWhile/TryThenWhile.swift:80:17: note: found this candidate
    public func thenWhile(@autoclosure test:  () -> Bool, body: () -> Result<()>) -> Result<()> {
                ^
/Users/jay/Coding/Swift/TrySwift/TryThenWhile/TryThenWhile.swift:98:17: note: found this candidate
    public func thenWhile(@autoclosure test:  () -> Bool, body: () -> ()) -> Result<()> {
                ^
/Users/jay/Coding/Swift/TrySwift/TryThenWhile/TryThenWhile.swift:156:15: error: enum case pattern cannot match values of the non-enum type '<<error type>>'
        case .Success(let res): XCTAssertEqual(res.unbox, 10, "Test 4 should have succeeded")
              ^
/Users/jay/Coding/Swift/TrySwift/TryThenWhile/TryThenWhile.swift:157:15: error: enum case pattern cannot match values of the non-enum type '<<error type>>'
        case .Failure(_): XCTFail("Test 4 failed")

Comments

Duplicate of 19776288 (Closed)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!