Skip to content

Instantly share code, notes, and snippets.

@airspeedswift
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airspeedswift/bdddbb23c2e941f5e835 to your computer and use it in GitHub Desktop.
Save airspeedswift/bdddbb23c2e941f5e835 to your computer and use it in GitHub Desktop.
Upconverted function returning tuple of optionals corrupts on destructuring return value
func f()->(Int,Int) {
return (1,1)
}
func g(f: ()->(Int?,Int?)) -> (Int,Int) {
let (a,b) = f()
return (a ?? 0, b ?? 0)
}
// ()->(Int,Int) is substitutable for
// ()->(Int?,Int?) so this compiles
let x = g(f)
// but results are corrupted
println(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment