Skip to content

Commit 352a44d

Browse files
committed
Attempt to explain buildLimitedAvailability better
1 parent 8b7826c commit 352a44d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

TSPL.docc/ReferenceManual/Attributes.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,11 +1640,9 @@ The additional result-building methods are as follows:
16401640
or to perform other postprocessing on a result before returning it.
16411641

16421642
- term `static func buildLimitedAvailability(_ component: Component) -> Component`:
1643-
Builds a partial result that propagates or erases type information
1643+
Builds a partial result that erases type information for
16441644
outside a compiler-control statement
16451645
that performs an availability check.
1646-
You can use this to erase type information
1647-
that varies between the conditional branches.
16481646

16491647
For example, the code below defines a simple result builder
16501648
that builds an array of integers.
@@ -1743,7 +1741,7 @@ into code that calls the static methods of the result builder type:
17431741
You can define an overload of `buildExpression(_:)`
17441742
that takes an argument of type `()` to handle assignments specifically.
17451743
- A branch statement that checks an availability condition
1746-
becomes a call to the `buildLimitedAvailability(_:)` method.
1744+
becomes a call to the `buildLimitedAvailability(_:)` method if one is defined.
17471745
This transformation happens before the transformation into a call to
17481746
`buildEither(first:)`, `buildEither(second:)`, or `buildOptional(_:)`.
17491747
You use the `buildLimitedAvailability(_:)` method to erase type information
@@ -1830,7 +1828,7 @@ into code that calls the static methods of the result builder type:
18301828
func draw() -> String { return content.draw() }
18311829
}
18321830
extension DrawingBuilder {
1833-
static func buildLimitedAvailability(_ content: Drawable) -> AnyDrawable {
1831+
static func buildLimitedAvailability(_ content: some Drawable) -> AnyDrawable {
18341832
return AnyDrawable(content: content)
18351833
}
18361834
}
@@ -1847,6 +1845,11 @@ into code that calls the static methods of the result builder type:
18471845

18481846
<!-- Comment block with swifttest for the code listing above is after the end of this bulleted list, due to tooling limitations. -->
18491847

1848+
Note that the above code compiled before
1849+
implementing the `buildLimitedAvailability` method,
1850+
as its role is not to enable the `if #available` syntax, but to
1851+
return a type that's always available.
1852+
18501853
- A branch statement becomes a series of nested calls to the
18511854
`buildEither(first:)` and `buildEither(second:)` methods.
18521855
The statements' conditions and cases are mapped onto
@@ -2222,7 +2225,7 @@ into code that calls the static methods of the result builder type:
22222225
func draw() -> String { return content.draw() }
22232226
}
22242227
-> extension DrawingBuilder {
2225-
static func buildLimitedAvailability(_ content: Drawable) -> AnyDrawable {
2228+
static func buildLimitedAvailability(_ content: some Drawable) -> AnyDrawable {
22262229
return AnyDrawable(content: content)
22272230
}
22282231
}

0 commit comments

Comments
 (0)