tera
1
What is the reason behind prohibiting throwing subscript setters?
struct S {
subscript(c c: Int) -> Int {
get { 0 }
set throws {} // π
}
subscript(d d: Int) -> Int {
get throws { 0 }
set throws {} // π
}
}
2 Likes
xwu
(Xiaodi Wu)
2
No one has implemented it.
It is hard, as discussed in SE-0310:
The main purpose of imposing this read-only restriction is to limit the scope of this proposal to a simple, useful, and easy-to-understand feature. Limiting effects specifiers to read-only properties and subscripts in this proposal does not prevent future proposals from offering them for mutable members. For more discussion of why effectful setters are tricky, see the "Extensions considered" section of this proposal.
4 Likes