Last active
August 29, 2015 14:07
-
-
Save wouter-swierstra/545d7142e7894f378d67 to your computer and use it in GitHub Desktop.
This file contains 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
// Two structs | |
struct One{ } | |
struct Two{ } | |
// Overloading the foo function - | |
// it should always take two arguments, one of type One; the other of type Two | |
func foo(x:One,y:Two) {return } | |
func foo(x:Two,y:One) {return } | |
// In this example, Swift's type checker figures out that x must have type Two | |
let bar = {x in | |
foo(One(),x) | |
} | |
// In this example, we construct a closure with two arguments. Now Swift's type | |
// checker can no longer figure out what the type of x and y must be. | |
// This seems strange... | |
let baz = {x,y in | |
foo(Two(),x) | |
foo(Two(),y) | |
} | |
To make the case even more concise: It's not even about the structs or using the variable twice in the closure:
func foo(x:String,y:Int) { return }
let bar = {x in
foo("string",x)
}
let baz = {x in
foo("string",x)
let y = 23
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This also doesn't type-check:
Neither does this: