You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -97,7 +97,7 @@ However, this approach has a few downsides:
97
97
***Repetitive:** Only the “Switch” component of the style name is important, since we already know that the modifier expects a type of `ToggleStyle`.
98
98
***Poor discoverability:** There is no autocomplete support to expose the available `ToggleStyle` types to choose from, so you have to know them in advance.
99
99
100
-
These downsides are impossible to avoid for generic parameters like above, which discourages generalizing functions. API designers should not have to chose between good design and easy-to-read code.
100
+
These downsides are impossible to avoid for generic parameters like above, which discourages generalizing functions. API designers should not have to choose between good design and easy-to-read code.
101
101
102
102
Instead, we could ideally support leading dot syntax for generic types with known protocol conformances, allowing syntax like this:
103
103
@@ -153,7 +153,7 @@ The type-checker is able to infer any protocol conformance requirements placed o
153
153
The second option is a much better choice that avoids having to do a global lookup and conformance checking and is consistent with semantics of leading dot syntax, namely, the requirement that result and base types of the chain have to be equivalent. This leads to a new rule: if the result type of a static member conforms to the declaring protocol, it should be possible to reference such a member on a protocol metatype, using leading dot syntax, by implicitly replacing the protocol with a conforming type.
154
154
155
155
156
-
> **Note:** If member returns a function type or an optional valuetype-checker considers “result type” (for purposes of base type inference) to be a result type of a function type and/or wrapped value of an optional type (if optional itself doesn’t conform to a required protocol). This enables calls to properties and optional chaining of member chains starting from protocol metatypes.
156
+
> **Note:** If a member returns a function type or an optional value, the type-checker considers “result type” (for the purposes of base type inference) to be a result type of a function type and/or wrapped value of an optional type (if `Optional` itself doesn’t conform to a required protocol). This enables calls to properties, and optional chaining of member chains, starting from protocol metatypes.
157
157
158
158
159
159
This approach works well for references without an explicit base, let’s consider an example:
@@ -177,11 +177,11 @@ applyStyle(.bordered)
177
177
```
178
178
179
179
180
-
In this case (`applyStyle(.bordered)`) the reference to the member `.bordered` is re-written to be `Bordered.bordered` in the type-checked AST.
180
+
In this case (`applyStyle(.bordered)`) the reference to the member `.bordered` is re-written to be `BorderedStyle.bordered` in the type-checked AST.
181
181
182
182
To make this work the type-checker would attempt to infer protocol conformance requirements from context, e.g. the call site of a generic function (in this case there is only one such requirement - the protocol `Style`), and propagate them to the type variable representing the implicit base type of the chain. If there is no other contextual information available, e.g. the result type couldn’t be inferred to some concrete type, the type-checker would attempt to bind base to the type of the inferred protocol requirement.
183
183
184
-
Member lookup filtering is adjusted to find static members on protocol metatype base but the `Self` part of the reference type is replaced with result type of the discovered member (looking through function types and IUOs) and additional conformance requirements are placed on it (the new `Self` type) to make sure that the new base does conform to the expected protocol.
184
+
Member lookup filtering is adjusted to find static members on a protocol metatype base, but the `Self` part of the reference type is replaced with the result type of the discovered member (looking through function types and IUOs) and additional conformance requirements are placed on it (the new `Self` type) to make sure that the new base does conform to the expected protocol.
0 commit comments