-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomers
Description
| Previous ID | SR-2145 |
| Radar | None |
| Original Reporter | fbartho (JIRA User) |
| Type | Bug |
Environment
-
Xcode: Version 8.0 beta 3 (8S174q)
-
Commandline tools: Xcode 8.0 (8S174q)
-
macOS: 10.11.6 (15G31)
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug, DiagnosticsQoI, StarterBug |
| Assignee | None |
| Priority | Medium |
md5: c713c996341946e49c76cdb770caa2f1
Issue Description:
1. Write a simple class that has optional member vars.
2. Add a lazy var, and prepare an initializer for a lazy member variable.
Example:
class Original {
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
}()
}3. Notice that there's a compile error with a fix-it on the return line suggesting to test for != nil instead
4. Click the fix-it to apply the suggested correction:
This produces the following output:
lazy var type: Foo = ({
return self.opt1 ? .one
: self.opt2 ? .two
: .unknown
}() != nil) /// Now a compiler error highlighting this lineExpected Result:
lazy var type: Foo = {
return (nil != self.opt1) ? .one
: (nil != self.opt2) ? .two
: .unknown
}()Reproduces in an iOS project & in a playground
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomers