Created
October 29, 2017 05:21
-
-
Save dduan/c96347a9a4794a6a4e95547a57a3daba to your computer and use it in GitHub Desktop.
Enum setter error reporting seems too simplistic?
This file contains hidden or 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
| enum E { | |
| final class P { var v = 0 } | |
| case a(P) | |
| var p: P { | |
| switch self { | |
| case .a(let p): return p | |
| } | |
| } | |
| var v: Int { | |
| get { return self.p.v } | |
| set { self.p.v = newValue } | |
| } | |
| func setV(_ newV: Int) { | |
| self.p.v = newV | |
| } | |
| } | |
| let a = E.a(E.P()) | |
| a.setV(1) // okay | |
| a.v = 2 // error: cannot assign to property: 'a' is a 'let' constant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment