Skip to content

Commit 7e8b12c

Browse files
Incorporate tech review from Slava
Co-authored-by: Slava Pestov <[email protected]>
1 parent c51f443 commit 7e8b12c

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

TSPL.docc/LanguageGuide/Generics.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,16 @@ like `T` and `MyTypeParameter`,
291291
to indicate that they're a placeholder for a *type*, not a value.
292292

293293
> Note:
294-
> If you don't need to name a type parameter or give it any constraints,
294+
> If you don't need to name a type parameter
295+
> and its generic type constraints are simple,
295296
> there's an alternate, lightweight syntax you can use instead,
296297
> as described in <doc:OpaqueTypes#Opaque-Parameter-Types>.
298+
<!--
299+
Comparison between this syntax and the lightweight syntax
300+
is in the Opaque Types chapter, not here ---
301+
the reader hasn't learned about constraints yet,
302+
so it wouldn't make sense to list what is/isn't supported.
303+
-->
297304

298305
## Generic Types
299306

TSPL.docc/LanguageGuide/OpaqueTypes.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,8 @@ func drawTwiceSome(_ shape: some Shape) -> String {
945945
```
946946

947947
The `drawTwiceGeneric(_:)` function
948-
uses a generic type parameter named `SomeShape`,
949-
and explicitly includes the protocol conformance requirement.
948+
declares a generic type parameter named `SomeShape`,
949+
with a constraint that requires `SomeShape` to conform to the `Shape` protocol.
950950
The `drawTwiceSome(_:)` function
951951
uses the type `some Shape` for its argument.
952952
This creates a new, unnamed, generic type parameter for the function
@@ -973,10 +973,14 @@ but there's no constraint that requires them to be the same type.
973973
When you call `combine(shape:with)`,
974974
you can pass two different shapes ---
975975
in this case, one triangle and one trapezoid.
976-
If you need to write a function
977-
that has multiple generic parameters
978-
and constrain them to be are all the same type,
979-
use the usual generic syntax instead.
976+
977+
Unlike the syntax for named generic type parameters,
978+
described in <docc:Generics> chapter,
979+
this lightweight syntax can't include
980+
a generic `where` clause or any same-type (`==`) constraints.
981+
In addition,
982+
using the lightweight syntax for very complex constraints
983+
can be hard to read.
980984

981985
<!--
982986
This source file is part of the Swift.org open source project

0 commit comments

Comments
 (0)