Swift 2: Erroneous "ambiguous use of" error message

Originator:gwendal.roue
Number:rdar://22852669 Date Originated:2015/09/25
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.0 (7A218)
Classification:Serious Bug Reproducible:Always
 
Summary:
Hello, this (minimal and artificial-looking) code won't compile, with an unexpected error message:

    protocol P1 { init() }
    protocol P2 { }

    extension Optional where Wrapped: P1 {
        func f() -> Wrapped {   // f1 variant
            return Wrapped()
        }
        func g() -> Wrapped {   // g1 variant
            return f()
        }
    }

    extension Optional where Wrapped: protocol<P1, P2> {
        func f() -> Wrapped {   // f2 variant
            return Wrapped()
        }
        func g() -> Wrapped {   // g2 variant
            return f()          // Expect f2 variant
        }
    }

Steps to Reproduce:
Compile the code above.

Expected Results:
The code compile, and the g2 variant of g() calls the f2 variant of f().

Actual Results:
The code does not compile, with the following error:

    Playground execution failed: playground.swift:18:16: error: ambiguous use of 'f()'
            return f()
                   ^
    playground.swift:5:10: note: found this candidate
        func f() -> Wrapped {
             ^
    playground.swift:14:10: note: found this candidate
        func f() -> Wrapped {
             ^


Version:
Xcode 7.0 (7A218
OSX 10.10.5 (14F27)

Comments


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!