Skip to content

Commit e6c7235

Browse files
authored
Add language annotations
1 parent 134547e commit e6c7235

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

proposals/NNNN-generalize-keypath-function-conversions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let f: (User) -> String? = { kp in { root in root[keyPath: kp] } }(\User.email)
7272

7373
While this proposal _mostly_ only makes previously invalid code valid, [@jrose](https://forums.swift.org/u/jrose) pointed out a case where this proposal could potentially change the meaning of existing code:
7474

75-
```
75+
```swift
7676
func evil<T, U>(_: (T) -> U) { print("generic") }
7777
func evil(_ x: (String) -> Bool?) { print("concrete") }
7878

@@ -89,19 +89,19 @@ evil({ kp in { $0[keyPath: kp] } }(\String.isEmpty)) // Prints 'concrete'
8989

9090
The circumstances necessary are exceedingly narrow to reproduce the above behavior. It is not enough merely to declare the `evil` overloads. The following naive reproduction attempt fails to compile, thus posing no source compatibility error:
9191

92-
```
92+
```swift
9393
struct S {
9494
let x: Bool
9595
}
9696

9797
func evil<T, U>(_: (T) -> U) { }
9898
func evil(_: (S) -> Bool?) { }
99-
evil(\S.x) //
99+
evil(\S.x)
100100
```
101101

102-
That this compilation fails seems to be a bug of its own. The additional ingredient appears to be overloading `x`—with the following additions, the snipped above compiles without error:
102+
That this compilation fails seems to be a bug of its own. The additional necessary ingredient appears to be overloading `x`—with the following additions, the snipped above compiles without error:
103103

104-
```
104+
```swift
105105
protocol P {}
106106
extension P {
107107
var x: Bool { true }

0 commit comments

Comments
 (0)