Skip to content

Commit e19dcac

Browse files
authored
Fix syntax highlighting in SE-0438 (#2471)
1 parent 76a0028 commit e19dcac

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

proposals/0438-metatype-keypath.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Metatype keypaths were briefly explored in the pitch for [SE-0254](https://forum
1919

2020
We propose to allow keypath expressions to define a reference to static properties. The following usage, which currently generates a compiler error, will be allowed as valid Swift code.
2121

22-
```
22+
```swift
2323
struct Bee {
2424
static let name = "honeybee"
2525
}
@@ -33,7 +33,7 @@ let kp = \Bee.Type.name
3333

3434
Keypath expressions where the first component refers to a static property will include `.Type` on their root types stated in the key path contextual type or in the key path literal. For example:
3535

36-
```
36+
```swift
3737
struct Bee {
3838
static let name = "honeybee"
3939
}
@@ -44,12 +44,12 @@ let kpWithLiteral = \Bee.Type.name // key path literal \Bee.Type
4444

4545
Attempting to write the above metatype keypath without including `.Type will trigger an error diagnostic:
4646

47-
```
47+
```swift
4848
let kpWithLiteral = \Bee.name // error: static member 'name' cannot be used on instance of type 'Bee'
4949
```
5050

5151
Keypath expressions where the component referencing a static property is not the first component do not require `.Type`:
52-
```
52+
```swift
5353
struct Species {
5454
static let isNative = true
5555
}
@@ -63,7 +63,7 @@ let kpSecondComponentIsStatic = \Wasp.species.isNative
6363
### Access semantics
6464

6565
Immutable static properties will form the read-only keypaths just like immutable instance properties.
66-
```
66+
```swift
6767
struct Tip {
6868
static let isIncluded = True
6969
let isVoluntary = False
@@ -73,7 +73,7 @@ let kpStaticImmutable: KeyPath<Tip.Type, Bool> = \.isIncluded
7373
let kpInstanceImmutable: KeyPath<Tip, Bool> = \.isVoluntary
7474
```
7575
However, unlike instance members, keypaths to mutable static properties will always conform to `ReferenceWritableKeyPath` because metatypes are reference types.
76-
```
76+
```swift
7777
struct Tip {
7878
static var total = 0
7979
var flatRate = 20
@@ -86,7 +86,7 @@ let kpInstanceMutable: WriteableKeyPath<Tip, Int> = \.flatRate
8686

8787
This feature breaks source compatibility for key path expressions that reference static properties after subscript overloads. For example, the compiler cannot differentiate between subscript keypath components by return type in the following:
8888

89-
```
89+
```swift
9090
struct S {
9191
static var count: Int { 42 }
9292
}
@@ -101,7 +101,7 @@ let kpViaSubscript = \Test.[42] // fails to typecheck
101101

102102
This keypath does not specify a contextual type, without which the key path value type is unknown. To form a keypath to the metatype subscript and return an `Int`, we can specify a contextual type with a value type of `S.Type` and chain the metatype keypath:
103103

104-
```
104+
```swift
105105
let kpViaSubscript: KeyPath<Test, S.Type> = \Test.[42]
106106
let kpAppended = kpViaSubscript.appending(path: \.count)
107107
```

0 commit comments

Comments
 (0)