Skip to content

Commit b0f35ec

Browse files
committed
Improve flow and make some details explicit
1 parent ab5fba0 commit b0f35ec

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

TSPL.docc/ReferenceManual/Types.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -910,21 +910,28 @@ that are part of the function's generic type parameters.
910910
For example, a function `someFunction<T>()`
911911
could return a value of type `T` or `Dictionary<String, T>`.
912912

913-
A parameter whose type is an opaque type
914-
is syntactic sugar for a parameter of generic type,
913+
Writing an opaque type for a parameter
914+
is syntactic sugar for using a generic type,
915915
without specifying a name for the generic type parameter.
916-
That is, the following declarations are equivalent,
917-
with `T1` and `T2` representing the unnamed generic type parameters:
916+
The implicit generic type parameter has a constraint
917+
that requires it to conform to the protocol named in the opaque type.
918+
If you write multiple opaque types,
919+
each one makes its own generic type parameter.
920+
For example, the following declarations are equivalent:
918921

919922
```swift
920923
func someFunction(x: some MyProtocol, y: some MyProtocol) { }
921924
func someFunction<T1: MyProtocol, T2: MyProtocol>(x: T1, y: T2) { }
922925
```
923926

924-
Because the generic types doesn't have a name,
925-
there's no way to refer to it in code.
927+
In the second declaration,
928+
because the generic type parameters `T1` and `T2` have names,
929+
you can refer use these types elsewhere in the code.
930+
In contrast,
931+
the generic type parameters in the first declaration
932+
don't have names and can't be referenced in other code.
926933

927-
You can't use this syntactic sugar on the type of a variadic parameter.
934+
You can't use an opaque type in the type of a variadic parameter.
928935

929936
You can't use an opaque type
930937
as a parameter to a function type being returned,

0 commit comments

Comments
 (0)