@@ -864,7 +864,8 @@ that conforms to a protocol or protocol composition,
864
864
without specifying the underlying concrete type.
865
865
866
866
Opaque types appear as the return type of a function or subscript,
867
- or the type of a property.
867
+ as the type of a parameter to a function, initializer, or subscript,
868
+ or as the type of a property.
868
869
Opaque types can't appear as part of a tuple type or a generic type,
869
870
such as the element type of an array or the wrapped type of an optional.
870
871
@@ -909,6 +910,35 @@ that are part of the function's generic type parameters.
909
910
For example, a function ` someFunction<T>() `
910
911
could return a value of type ` T ` or ` Dictionary<String, T> ` .
911
912
913
+ A parameter whose type is an opaque type
914
+ is syntactic sugar for a parameter of generic type,
915
+ 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:
918
+
919
+ ``` swift
920
+ func someFunction (x : some MyProtocol, y : some MyProtocol) { }
921
+ func someFunction <T1 : MyProtocol , T2 : MyProtocol >(x : T1, y : T2) { }
922
+ ```
923
+
924
+ Because the generic types doesn't have a name,
925
+ there's no way to refer to it in code.
926
+
927
+ You can't use this syntactic sugar on the type of a variadic parameter.
928
+
929
+ You can't use an opaque type
930
+ as a parameter to a function type being returned,
931
+ or as a parameter in a parameter type that's a function type.
932
+ In these positions,
933
+ the function's caller would have to construct a value
934
+ of that unknown type.
935
+
936
+ ``` swift
937
+ protocol MyProtocol { }
938
+ func badFunction () -> (some MyProtocol) -> Void { } // Error
939
+ func anotherBadFunction (callback : (some MyProtocol) -> Void ) { } // Error
940
+ ```
941
+
912
942
> Grammar of an opaque type:
913
943
>
914
944
> * opaque-type* → ** ` some ` ** * type*
0 commit comments