Skip to content

Commit aa1c9de

Browse files
authored
Minor fixes (#70)
2 parents 3145188 + a8d0591 commit aa1c9de

File tree

5 files changed

+212
-159
lines changed

5 files changed

+212
-159
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.md linguist-detectable=true
22
*.md linguist-documentation=false
3+
*.md diff=markdown

Sources/TSPL/TSPL.docc/LanguageGuide/Initialization.md

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,14 @@ convenience init(<#parameters#>) {
925925
To simplify the relationships between designated and convenience initializers,
926926
Swift applies the following three rules for delegation calls between initializers:
927927

928-
- term **Rule 1**: A designated initializer must call a designated initializer from its immediate superclass.
929-
- term **Rule 2**: A convenience initializer must call another initializer from the *same* class.
930-
- term **Rule 3**: A convenience initializer must ultimately call a designated initializer.
928+
- term **Rule 1**:
929+
A designated initializer must call a designated initializer from its immediate superclass.
930+
931+
- term **Rule 2**:
932+
A convenience initializer must call another initializer from the *same* class.
933+
934+
- term **Rule 3**:
935+
A convenience initializer must ultimately call a designated initializer.
931936

932937
A simple way to remember this is:
933938

@@ -990,28 +995,34 @@ by another initializer unexpectedly.
990995
Swift's compiler performs four helpful safety-checks to make sure that
991996
two-phase initialization is completed without error:
992997

993-
- term **Safety check 1**: A designated initializer must ensure that all of the properties introduced by its class
994-
are initialized before it delegates up to a superclass initializer.
998+
- term **Safety check 1**:
999+
A designated initializer must ensure that all of the properties introduced by its class
1000+
are initialized before it delegates up to a superclass initializer.
9951001

9961002
As mentioned above,
9971003
the memory for an object is only considered fully initialized
9981004
once the initial state of all of its stored properties is known.
9991005
In order for this rule to be satisfied, a designated initializer must make sure that
10001006
all of its own properties are initialized before it hands off up the chain.
10011007

1002-
- term **Safety check 2**: A designated initializer must delegate up to a superclass initializer
1003-
before assigning a value to an inherited property.
1004-
If it doesn't, the new value the designated initializer assigns
1005-
will be overwritten by the superclass as part of its own initialization.
1006-
- term **Safety check 3**: A convenience initializer must delegate to another initializer
1007-
before assigning a value to *any* property
1008-
(including properties defined by the same class).
1009-
If it doesn't, the new value the convenience initializer assigns
1010-
will be overwritten by its own class's designated initializer.
1011-
- term **Safety check 4**: An initializer can't call any instance methods,
1012-
read the values of any instance properties,
1013-
or refer to `self` as a value
1014-
until after the first phase of initialization is complete.
1008+
- term **Safety check 2**:
1009+
A designated initializer must delegate up to a superclass initializer
1010+
before assigning a value to an inherited property.
1011+
If it doesn't, the new value the designated initializer assigns
1012+
will be overwritten by the superclass as part of its own initialization.
1013+
1014+
- term **Safety check 3**:
1015+
A convenience initializer must delegate to another initializer
1016+
before assigning a value to *any* property
1017+
(including properties defined by the same class).
1018+
If it doesn't, the new value the convenience initializer assigns
1019+
will be overwritten by its own class's designated initializer.
1020+
1021+
- term **Safety check 4**:
1022+
An initializer can't call any instance methods,
1023+
read the values of any instance properties,
1024+
or refer to `self` as a value
1025+
until after the first phase of initialization is complete.
10151026

10161027
The class instance isn't fully valid until the first phase ends.
10171028
Properties can only be accessed, and methods can only be called,
@@ -1431,13 +1442,16 @@ and can inherit your superclass initializers with minimal effort whenever it's s
14311442
Assuming that you provide default values for any new properties you introduce in a subclass,
14321443
the following two rules apply:
14331444

1434-
- term **Rule 1**: If your subclass doesn't define any designated initializers,
1435-
it automatically inherits all of its superclass designated initializers.
1436-
- term **Rule 2**: If your subclass provides an implementation of
1437-
*all* of its superclass designated initializers ---
1438-
either by inheriting them as per rule 1,
1439-
or by providing a custom implementation as part of its definition ---
1440-
then it automatically inherits all of the superclass convenience initializers.
1445+
- term **Rule 1**:
1446+
If your subclass doesn't define any designated initializers,
1447+
it automatically inherits all of its superclass designated initializers.
1448+
1449+
- term **Rule 2**:
1450+
If your subclass provides an implementation of
1451+
*all* of its superclass designated initializers ---
1452+
either by inheriting them as per rule 1,
1453+
or by providing a custom implementation as part of its definition ---
1454+
then it automatically inherits all of the superclass convenience initializers.
14411455

14421456
These rules apply even if your subclass adds further convenience initializers.
14431457

Sources/TSPL/TSPL.docc/ReferenceManual/Attributes.md

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,42 +1364,49 @@ they default to being the same as `Component`.
13641364

13651365
The result-building methods are as follows:
13661366

1367-
<!--
1368-
start of term/defn list
1369-
-->
1370-
1371-
- term `static func buildBlock(_ components: Component...) -> Component`: Combines an array of partial results into a single partial result.
1372-
A result builder must implement this method.
1373-
- term `static func buildOptional(_ component: Component?) -> Component`: Builds a partial result from a partial result that can be `nil`.
1374-
Implement this method to support `if` statements
1375-
that don’t include an `else` clause.
1376-
- term `static func buildEither(first: Component) -> Component`: Builds a partial result whose value varies depending on some condition.
1377-
Implement both this method and `buildEither(second:)`
1378-
to support `switch` statements
1379-
and `if` statements that include an `else` clause.
1380-
- term `static func buildEither(second: Component) -> Component`: Builds a partial result whose value varies depending on some condition.
1381-
Implement both this method and `buildEither(first:)`
1382-
to support `switch` statements
1383-
and `if` statements that include an `else` clause.
1384-
- term `static func buildArray(_ components: [Component]) -> Component`: Builds a partial result from an array of partial results.
1385-
Implement this method to support `for` loops.
1386-
- term `static func buildExpression(_ expression: Expression) -> Component`: Builds a partial result from an expression.
1387-
You can implement this method to perform preprocessing ---
1388-
for example, converting expressions to an internal type ---
1389-
or to provide additional information for type inference at use sites.
1390-
- term `static func buildFinalResult(_ component: Component) -> FinalResult`: Builds a final result from a partial result.
1391-
You can implement this method as part of a result builder
1392-
that uses a different type for partial and final results,
1393-
or to perform other postprocessing on a result before returning it.
1394-
- term `static func buildLimitedAvailability(_ component: Component) -> Component`: Builds a partial result that propagates or erases type information
1395-
outside a compiler-control statement
1396-
that performs an availability check.
1397-
You can use this to erase type information
1398-
that varies between the conditional branches.
1399-
1400-
<!--
1401-
end of term/defn list
1402-
-->
1367+
- term `static func buildBlock(_ components: Component...) -> Component`:
1368+
Combines an array of partial results into a single partial result.
1369+
A result builder must implement this method.
1370+
1371+
- term `static func buildOptional(_ component: Component?) -> Component`:
1372+
Builds a partial result from a partial result that can be `nil`.
1373+
Implement this method to support `if` statements
1374+
that don’t include an `else` clause.
1375+
1376+
- term `static func buildEither(first: Component) -> Component`:
1377+
Builds a partial result whose value varies depending on some condition.
1378+
Implement both this method and `buildEither(second:)`
1379+
to support `switch` statements
1380+
and `if` statements that include an `else` clause.
1381+
1382+
- term `static func buildEither(second: Component) -> Component`:
1383+
Builds a partial result whose value varies depending on some condition.
1384+
Implement both this method and `buildEither(first:)`
1385+
to support `switch` statements
1386+
and `if` statements that include an `else` clause.
1387+
1388+
- term `static func buildArray(_ components: [Component]) -> Component`:
1389+
Builds a partial result from an array of partial results.
1390+
Implement this method to support `for` loops.
1391+
1392+
- term `static func buildExpression(_ expression: Expression) -> Component`:
1393+
Builds a partial result from an expression.
1394+
You can implement this method to perform preprocessing ---
1395+
for example, converting expressions to an internal type ---
1396+
or to provide additional information for type inference at use sites.
1397+
1398+
- term `static func buildFinalResult(_ component: Component) -> FinalResult`:
1399+
Builds a final result from a partial result.
1400+
You can implement this method as part of a result builder
1401+
that uses a different type for partial and final results,
1402+
or to perform other postprocessing on a result before returning it.
1403+
1404+
- term `static func buildLimitedAvailability(_ component: Component) -> Component`:
1405+
Builds a partial result that propagates or erases type information
1406+
outside a compiler-control statement
1407+
that performs an availability check.
1408+
You can use this to erase type information
1409+
that varies between the conditional branches.
14031410

14041411
For example, the code below defines a simple result builder
14051412
that builds an array of integers.

0 commit comments

Comments
 (0)