Last active
August 29, 2015 14:05
-
-
Save bjhomer/b5187a119fe6334989fb to your computer and use it in GitHub Desktop.
This does not compile.
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
class Foo { | |
var closure: () -> () = {} | |
init() {} | |
func nothing() {} | |
func setupClosure() { | |
closure = { | |
[weak self] in | |
self?.nothing() // <-- this returns a "Void?", which means that the rhs's | |
// inferred type does not match the lhs's type. | |
} | |
} | |
func setupClosure2() { | |
closure = { | |
[weak self] () -> () in | |
self?.nothing() // <-- Also fails to compile, because inferred type does not | |
// match explicit type declaration | |
} | |
} | |
func setupClosure3() { | |
closure = { | |
[weak self] in | |
self?.nothing(); return // <-- This works, because it's no longer a single-expression | |
// closure, and thus it's no longer inferring a "Void?" | |
// return type. | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment