Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions TSPL.docc/LanguageGuide/BasicOperators.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,26 +506,26 @@ with the `<` operator because the `<` operator can't be applied to
`Bool` values.

```swift
("blue", -1) < ("purple", 1) // OK, evaluates to true
("blue", false) < ("purple", true) // Error because < can't compare Boolean values
("blue", -1) < ("purple", 1) // OK: Evaluates to true.
("blue", false) < ("purple", true) // Error: Can't use < to compare Boolean values.
```

<!--
- test: `tuple-comparison-operators-err`

```swifttest
>> _ =
-> ("blue", -1) < ("purple", 1) // OK, evaluates to true
-> ("blue", -1) < ("purple", 1) // OK: Evaluates to true.
>> _ =
-> ("blue", false) < ("purple", true) // Error because < can't compare Boolean values
-> ("blue", false) < ("purple", true) // Error: Can't use < to compare Boolean values.
!$ error: type '(String, Bool)' cannot conform to 'Comparable'
!! ("blue", false) < ("purple", true) // Error because < can't compare Boolean values
!! ("blue", false) < ("purple", true) // Error: Can't use < to compare Boolean values.
!! ^
!$ note: only concrete types such as structs, enums and classes can conform to protocols
!! ("blue", false) < ("purple", true) // Error because < can't compare Boolean values
!! ("blue", false) < ("purple", true) // Error: Can't use < to compare Boolean values.
!! ^
!$ note: required by referencing operator function '<' on 'Comparable' where 'Self' = '(String, Bool)'
!! ("blue", false) < ("purple", true) // Error because < can't compare Boolean values
!! ("blue", false) < ("purple", true) // Error: Can't use < to compare Boolean values.
!! ^
```
-->
Expand Down
4 changes: 2 additions & 2 deletions TSPL.docc/LanguageGuide/Closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ as discussed in <doc:ClassesAndStructures#Structures-and-Enumerations-Are-Value-
struct SomeStruct {
var x = 10
mutating func doSomething() {
someFunctionWithNonescapingClosure { x = 200 } // Ok
someFunctionWithNonescapingClosure { x = 200 } // OK
someFunctionWithEscapingClosure { x = 100 } // Error
}
}
Expand All @@ -1066,7 +1066,7 @@ struct SomeStruct {
-> struct SomeStruct {
var x = 10
mutating func doSomething() {
someFunctionWithNonescapingClosure { x = 200 } // Ok
someFunctionWithNonescapingClosure { x = 200 } // OK
someFunctionWithEscapingClosure { x = 100 } // Error
}
}
Expand Down
16 changes: 8 additions & 8 deletions TSPL.docc/LanguageGuide/MemorySafety.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func increment(_ number: inout Int) {
}

increment(&stepSize)
// Error: conflicting accesses to stepSize
// Error: Conflicting accesses to stepSize.
```

<!--
Expand All @@ -257,7 +257,7 @@ increment(&stepSize)
}

-> increment(&stepSize)
// Error: conflicting accesses to stepSize
// Error: Conflicting accesses to stepSize.
xx Simultaneous accesses to 0x10e8667d8, but modification requires exclusive access.
xx Previous access (a modification) started at (0x10e86b032).
xx Current access (a read) started at:
Expand Down Expand Up @@ -334,7 +334,7 @@ var playerOneScore = 42
var playerTwoScore = 30
balance(&playerOneScore, &playerTwoScore) // OK
balance(&playerOneScore, &playerOneScore)
// Error: conflicting accesses to playerOneScore
// Error: Conflicting accesses to playerOneScore.
```

<!--
Expand All @@ -350,7 +350,7 @@ balance(&playerOneScore, &playerOneScore)
-> var playerTwoScore = 30
-> balance(&playerOneScore, &playerTwoScore) // OK
-> balance(&playerOneScore, &playerOneScore)
// Error: conflicting accesses to playerOneScore
// Error: Conflicting accesses to playerOneScore.
!$ error: inout arguments are not allowed to alias each other
!! balance(&playerOneScore, &playerOneScore)
!! ^~~~~~~~~~~~~~~
Expand Down Expand Up @@ -502,15 +502,15 @@ there's a conflict:

```swift
oscar.shareHealth(with: &oscar)
// Error: conflicting accesses to oscar
// Error: Conflicting accesses to oscar.
```

<!--
- test: `memory-player-share-with-self`

```swifttest
-> oscar.shareHealth(with: &oscar)
// Error: conflicting accesses to oscar
// Error: Conflicting accesses to oscar.
!$ error: inout arguments are not allowed to alias each other
!! oscar.shareHealth(with: &oscar)
!! ^~~~~~
Expand Down Expand Up @@ -556,7 +556,7 @@ produces a conflict:
```swift
var playerInformation = (health: 10, energy: 20)
balance(&playerInformation.health, &playerInformation.energy)
// Error: conflicting access to properties of playerInformation
// Error: Conflicting access to properties of playerInformation.
```

<!--
Expand All @@ -570,7 +570,7 @@ balance(&playerInformation.health, &playerInformation.energy)
>> }
-> var playerInformation = (health: 10, energy: 20)
-> balance(&playerInformation.health, &playerInformation.energy)
// Error: conflicting access to properties of playerInformation
// Error: Conflicting access to properties of playerInformation.
xx Simultaneous accesses to 0x10794d848, but modification requires exclusive access.
xx Previous access (a modification) started at (0x107952037).
xx Current access (a modification) started at:
Expand Down
12 changes: 6 additions & 6 deletions TSPL.docc/LanguageGuide/OpaqueTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ that includes a special case for squares:
```swift
func invalidFlip<T: Shape>(_ shape: T) -> some Shape {
if shape is Square {
return shape // Error: return types don't match
return shape // Error: Return types don't match.
}
return FlippedShape(shape: shape) // Error: return types don't match
return FlippedShape(shape: shape) // Error: Return types don't match.
}
```

Expand All @@ -395,18 +395,18 @@ func invalidFlip<T: Shape>(_ shape: T) -> some Shape {
>> }
-> func invalidFlip<T: Shape>(_ shape: T) -> some Shape {
if shape is Square {
return shape // Error: return types don't match
return shape // Error: Return types don't match.
}
return FlippedShape(shape: shape) // Error: return types don't match
return FlippedShape(shape: shape) // Error: Return types don't match.
}
!$ error: function declares an opaque return type 'some Shape', but the return statements in its body do not have matching underlying types
!! func invalidFlip<T: Shape>(_ shape: T) -> some Shape {
!! ^ ~~~~~~~~~~
!$ note: return statement has underlying type 'T'
!! return shape // Error: return types don't match
!! return shape // Error: Return types don't match.
!! ^
!$ note: return statement has underlying type 'FlippedShape<T>'
!! return FlippedShape(shape: shape) // Error: return types don't match
!! return FlippedShape(shape: shape) // Error: Return types don't match.
!! ^
```
-->
Expand Down
8 changes: 4 additions & 4 deletions TSPL.docc/ReferenceManual/Declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3238,7 +3238,7 @@ extension Array: Serializable where Element == String {
// implementation
}
}
// Error: redundant conformance of 'Array<Element>' to protocol 'Serializable'
// Error: Redundant conformance of 'Array<Element>' to protocol 'Serializable'.
```

<!--
Expand All @@ -3261,7 +3261,7 @@ extension Array: Serializable where Element == String {
>> return 0
-> }
}
// Error: redundant conformance of 'Array<Element>' to protocol 'Serializable'
// Error: Redundant conformance of 'Array<Element>' to protocol 'Serializable'.
!$ error: conflicting conformance of 'Array<Element>' to protocol 'Serializable'; there cannot be more than one conformance, even with different conditional bounds
!! extension Array: Serializable where Element == String {
!! ^
Expand Down Expand Up @@ -3376,7 +3376,7 @@ resulting in an error:
```swift
extension Array: Loggable where Element: TitledLoggable { }
extension Array: Loggable where Element: MarkedLoggable { }
// Error: redundant conformance of 'Array<Element>' to protocol 'Loggable'
// Error: Redundant conformance of 'Array<Element>' to protocol 'Loggable'.
```

<!--
Expand All @@ -3388,7 +3388,7 @@ extension Array: Loggable where Element: MarkedLoggable { }
>> protocol TitledLoggable : Loggable { }
-> extension Array: Loggable where Element: TitledLoggable { }
extension Array: Loggable where Element: MarkedLoggable { }
// Error: redundant conformance of 'Array<Element>' to protocol 'Loggable'
// Error: Redundant conformance of 'Array<Element>' to protocol 'Loggable'.
!$ error: conflicting conformance of 'Array<Element>' to protocol 'Loggable'; there cannot be more than one conformance, even with different conditional bounds
!! extension Array: Loggable where Element: MarkedLoggable { }
!! ^
Expand Down
36 changes: 18 additions & 18 deletions TSPL.docc/ReferenceManual/Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ that operator applies to the whole infix expression.
That said, you can use parentheses to be explicit about the scope of the operator's application.

```swift
// try applies to both function calls
// Writing 'try' applies to both function calls.
sum = try someThrowingFunction() + anotherThrowingFunction()

// try applies to both function calls
// Writing 'try' applies to both function calls.
sum = try (someThrowingFunction() + anotherThrowingFunction())

// Error: try applies only to the first function call
// Error: Writing 'try' applies only to the first function call.
sum = (try someThrowingFunction()) + anotherThrowingFunction()
```

Expand All @@ -122,13 +122,13 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction()
>> func someThrowingFunction() throws -> Int { return 10 }
>> func anotherThrowingFunction() throws -> Int { return 5 }
>> var sum = 0
// try applies to both function calls
// Writing 'try' applies to both function calls.
-> sum = try someThrowingFunction() + anotherThrowingFunction()

// try applies to both function calls
// Writing 'try' applies to both function calls.
-> sum = try (someThrowingFunction() + anotherThrowingFunction())

// Error: try applies only to the first function call
// Error: Writing 'try' applies only to the first function call.
-> sum = (try someThrowingFunction()) + anotherThrowingFunction()
!$ error: call can throw but is not marked with 'try'
!! sum = (try someThrowingFunction()) + anotherThrowingFunction()
Expand Down Expand Up @@ -215,13 +215,13 @@ That said, you can use parentheses
to be explicit about the scope of the operator's application.

```swift
// await applies to both function calls
// Writing 'await' applies to both function calls.
sum = await someAsyncFunction() + anotherAsyncFunction()

// await applies to both function calls
// Writing 'await' applies to both function calls.
sum = await (someAsyncFunction() + anotherAsyncFunction())

// Error: await applies only to the first function call
// Error: Writing 'await' applies only to the first function call.
sum = (await someAsyncFunction()) + anotherAsyncFunction()
```

Expand All @@ -233,13 +233,13 @@ sum = (await someAsyncFunction()) + anotherAsyncFunction()
>> func anotherAsyncFunction() async -> Int { return 5 }
>> func f() async {
>> var sum = 0
// await applies to both function calls
// Writing 'await' applies to both function calls.
-> sum = await someAsyncFunction() + anotherAsyncFunction()

// await applies to both function calls
// Writing 'await' applies to both function calls.
-> sum = await (someAsyncFunction() + anotherAsyncFunction())

// Error: await applies only to the first function call
// Error: Writing 'await' applies only to the first function call.
-> sum = (await someAsyncFunction()) + anotherAsyncFunction()
>> _ = sum // Suppress irrelevant written-but-not-read warning
>> }
Expand Down Expand Up @@ -1231,15 +1231,15 @@ see <doc:AutomaticReferenceCounting#Resolving-Strong-Reference-Cycles-for-Closur

```swifttest
>> var a = 12
>> let c1 = { [a] in return a } // OK -- no async or throws
>> let c2 = { [a] async in return a } // ERROR
>> let c3 = { [a] async -> in return a } // ERROR
>> let c4 = { [a] () async -> Int in return a } // OK -- has () and ->
>> let c1 = { [a] in return a } // OK: No async or throws
>> let c2 = { [a] async in return a } // Error
>> let c3 = { [a] async -> in return a } // Error
>> let c4 = { [a] () async -> Int in return a } // OK: Has () and ->
!$ error: expected expression
!! let c3 = { [a] async -> in return a } // ERROR
!! let c3 = { [a] async -> in return a } // Error
!! ^
!$ error: unable to infer type of a closure parameter 'async' in the current context
!! let c2 = { [a] async in return a } // ERROR
!! let c2 = { [a] async in return a } // Error
!! ^
// NOTE: The error message for c3 gets printed by the REPL before the c2 error.
```
Expand Down
14 changes: 7 additions & 7 deletions TSPL.docc/ReferenceManual/Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,21 @@ that name is part of the type.

```swift
var someTuple = (top: 10, bottom: 12) // someTuple is of type (top: Int, bottom: Int)
someTuple = (top: 4, bottom: 42) // OK: names match
someTuple = (9, 99) // OK: names are inferred
someTuple = (left: 5, right: 5) // Error: names don't match
someTuple = (top: 4, bottom: 42) // OK: Names match.
someTuple = (9, 99) // OK: Names are inferred.
someTuple = (left: 5, right: 5) // Error: Names don't match.
```

<!--
- test: `tuple-type-names`

```swifttest
-> var someTuple = (top: 10, bottom: 12) // someTuple is of type (top: Int, bottom: Int)
-> someTuple = (top: 4, bottom: 42) // OK: names match
-> someTuple = (9, 99) // OK: names are inferred
-> someTuple = (left: 5, right: 5) // Error: names don't match
-> someTuple = (top: 4, bottom: 42) // OK: Names match.
-> someTuple = (9, 99) // OK: Names are inferred.
-> someTuple = (left: 5, right: 5) // Error: Names don't match.
!$ error: cannot assign value of type '(left: Int, right: Int)' to type '(top: Int, bottom: Int)'
!! someTuple = (left: 5, right: 5) // Error: names don't match
!! someTuple = (left: 5, right: 5) // Error: Names don't match.
!! ^~~~~~~~~~~~~~~~~~~
```
-->
Expand Down