Created
July 21, 2016 21:42
-
-
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
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 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 | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://bugs.swift.org/browse/SR-2145