Skip to content

Instantly share code, notes, and snippets.

@fbartho
Created July 21, 2016 21:42
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 fbartho/c5d3ae4380f522dd68c86b64998ea4e4 to your computer and use it in GitHub Desktop.
Save fbartho/c5d3ae4380f522dd68c86b64998ea4e4 to your computer and use it in GitHub Desktop.
Xcode8 beta 3: Nested Ternaries operating on optionals in a lazy-var initializer have a fixit that grabs the wrong block to fixup
class Original {
var opt1: String? = nil
var opt2: String? = nil
enum Foo : String {
case unknown
case one
case two
}
// Compile flags an error w/ fixit suggestion on line 11 relating to not using optionals directly as booleans
lazy var type: Foo = {
return self.opt1 ? .one
: self.opt2 ? .two
: .unknown
}()
}
// This is what Xcode8 Beta 3 produced when applying the fix-it
class FixItCompletion {
var opt1: String? = nil
var opt2: String? = nil
enum Foo : String {
case unknown
case one
case two
}
lazy var type: Foo = ({
return self.opt1 ? .one
: self.opt2 ? .two
: .unknown
}() != nil) /// Now an error highlighting this line
}
// This is the expected result
class ExpectedOutcome {
var opt1: String? = nil
var opt2: String? = nil
enum Foo : String {
case unknown
case one
case two
}
lazy var type: Foo = {
return (nil != self.opt1) ? .one
: (nil != self.opt2) ? .two
: .unknown
}()
}
@fbartho
Copy link
Author

fbartho commented Jul 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment