Skip to content

Instantly share code, notes, and snippets.

@dduan
Created October 29, 2017 05:21
Show Gist options
  • Select an option

  • Save dduan/c96347a9a4794a6a4e95547a57a3daba to your computer and use it in GitHub Desktop.

Select an option

Save dduan/c96347a9a4794a6a4e95547a57a3daba to your computer and use it in GitHub Desktop.
Enum setter error reporting seems too simplistic?
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