I was trying to write a wrapper around InlineArray with a borrowing & mutating subscript that forwards to the array's subscript (to get a feel for it), but I unexpectedly ended up with an error inside my mutating getter.
public struct Vec4<Element: Numeric> {
var storage: [4 of Element]
public init(_ x: Element, _ y: Element, _ z: Element, _ w: Element) {
storage = [x, y, z, w]
}
public subscript(index: Int) -> Element {
borrow { storage[index] }
mutate { &storage[index] }
}
}
The error is:
main.swift:8:14: error: invalid return value from a mutate accessor
6 | public subscript(index: Int) -> Element {
7 | borrow { storage[index] }
8 | mutate { &storage[index] }
| |- error: invalid return value from a mutate accessor
| `- note: mutate accessors can return stored properties, computed properties with mutate accessors or global 'let' declarations
9 | }
10 | }
Am I holding it wrong, or should I file a bug report?