Skip to content

Commit 11d5c23

Browse files
committed
Incorporate pitch thread feedback
1 parent 9938185 commit 11d5c23

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

proposals/NNNN-allow-additional-args-to-dynamicmemberlookup-subscripts.md

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ let _: String = C().member // (5); no ambiguity
211211
let _: String? = C().member // (6) preferred over (5); ⚠️ previously (5) ⚠️
212212
```
213213

214-
This last case is the only source of behavior change: (6) was previously not considered a valid candidate, but has a return type more specific than (5**, and is now picked at a callsite.
214+
This last case is the only source of behavior change: (6) was previously not considered a valid candidate, but has a return type more specific than (5), and is now picked at a callsite.
215215

216-
**In practice, it is expected that this situation is exceedingly rare.**
216+
In practice, it is expected that this situation is exceedingly rare.
217217

218218
## ABI compatibility
219219

@@ -225,45 +225,51 @@ The changes in this proposal require the adoption of a new version of the Swift
225225

226226
## Alternatives considered
227227

228-
The main alternative to this proposal is to not implement it. This is possible to work around using explicit methods such as `get()` and `set(_:)`:
229-
230-
```swift
231-
@dynamicMemberLookup
232-
struct Value {
233-
struct Property {
234-
func get(
235-
function: StaticString = #function,
236-
file: StaticString = #file,
237-
line: UInt = #line
238-
) -> Value {
239-
...
240-
}
241-
242-
func set(
243-
_ value: Value,
244-
function: StaticString = #function,
245-
file: StaticString = #file,
246-
line: UInt = #line
247-
) {
248-
...
249-
}
250-
}
251-
252-
subscript(dynamicMember member: String) -> Property { ... }
253-
}
254-
255-
let x: Value = ...
256-
let _ = x.member.get() // x.member
257-
x.member.set(Value(42)) // x.member = Value(42)
258-
```
259-
260-
However, this feels non-idiomatic, and for long chains of getters and setters, can become cumbersome:
261-
262-
```swift
263-
let x: Value = ...
264-
let _ = x.member.get().inner.get().nested.get() // x.member.inner.nested
265-
x.member.get().inner.get().nested.set(Value(42)) // x.member.inner.nested = Value(42)
266-
```
228+
The main alternative to this proposal is to not implement it, as:
229+
1. It was noted in [the pitch thread](https://forums.swift.org/t/pitch-allow-additional-arguments-to-dynamicmemberlookup-subscripts/79558) that allowing additional arguments to dynamic member lookup widens the gap in capabilities between dynamic members and regular members — dynamic members would be able to
230+
a. Have caller side effects (i.e., have access to `#function`, `#file`, `#line`, etc.),
231+
b. Constrain themselves via generics, and
232+
c. Apply isolation to themselves via `#isolation`
233+
where regular members cannot. However, (a) and (c) are not considered an imbalance in functionality but instead are the raison d'être of this proposal. (b) is also already possible today as dynamic member subscripts can be constrained via generics (and this is often used with keypath-based lookup).
234+
2. This is possible to work around using explicit methods such as `get()` and `set(_:)`:
235+
236+
```swift
237+
@dynamicMemberLookup
238+
struct Value {
239+
struct Property {
240+
func get(
241+
function: StaticString = #function,
242+
file: StaticString = #file,
243+
line: UInt = #line
244+
) -> Value {
245+
...
246+
}
247+
248+
func set(
249+
_ value: Value,
250+
function: StaticString = #function,
251+
file: StaticString = #file,
252+
line: UInt = #line
253+
) {
254+
...
255+
}
256+
}
257+
258+
subscript(dynamicMember member: String) -> Property { ... }
259+
}
260+
261+
let x: Value = ...
262+
let _ = x.member.get() // x.member
263+
x.member.set(Value(42)) // x.member = Value(42)
264+
```
265+
266+
However, this feels non-idiomatic, and for long chains of getters and setters, can become cumbersome:
267+
268+
```swift
269+
let x: Value = ...
270+
let _ = x.member.get().inner.get().nested.get() // x.member.inner.nested
271+
x.member.get().inner.get().nested.set(Value(42)) // x.member.inner.nested = Value(42)
272+
```
267273

268274
### Source compatibility
269275

0 commit comments

Comments
 (0)