Created
June 11, 2019 21:58
-
-
Save krzyzanowskim/2746f2fa4b816b19f38196d27b741994 to your computer and use it in GitHub Desktop.
throwing closure parameter results in different resolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A {} | |
// foo | |
func foo<T>(_ v: T, handler: () -> Void) -> T { | |
print("regular") | |
return v | |
} | |
func foo<T>(_ v: T?, handler: () throws -> Void) rethrows -> T? { | |
print("optional") | |
return v | |
} | |
// bar | |
func bar<T>(_ v: T, handler: () -> Void) -> T { | |
print("regular") | |
return v | |
} | |
func bar<T>(_ v: T?, handler: () -> Void) -> T? { | |
print("optional") | |
return v | |
} | |
let result1: A? = foo(A(), handler: {}) // error: ambiguous use of 'foo(_:handler:)' | |
let result2: A? = bar(A(), handler: {}) // ok, "optional" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment