Skip to content

Commit 5949add

Browse files
authored
Revise SE-0491 with carveout for generic params (#2970)
During the review, Slava Pestov explained that it didn’t make sense to try to apply a module selector to a member type whose base was a generic parameter, as the member type will always represent the union of all associated types by that name. Edit the proposal to specify that module selectors are not valid in this position.
1 parent d4fbb38 commit 5949add

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

proposals/0491-module-selectors.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,28 @@ some other language feature has ruled out. For example, if a declaration is
476476
inaccessible because of access control or hasn't been imported into the current
477477
source file, a module selector will not allow it to be accessed.
478478

479+
#### Member types of type parameters
480+
481+
A member type of a type parameter must not be qualified by a module selector.
482+
483+
```swift
484+
func fn<T: Identifiable>(_: T) where T.Swift::ID == Int { // not allowed
485+
...
486+
}
487+
```
488+
489+
This is because, when a generic parameter conforms to two protocols that have
490+
associated types with the same name, the member type actually refers to *both*
491+
of those associated types. It doesn't make sense to use a module name to select
492+
one associated type or the other--it will always encompass both of them.
493+
494+
(In some cases, a type parameter's member type might end up referring to a
495+
concrete type—typically a typealias in a protocol extension–which
496+
theoretically *could* be disambiguated in this way. However, in these
497+
situations you could always use the protocol instead of the generic parameter
498+
as the base (and apply a module selector to it if needed), so we've chosen not
499+
to make an exception for them.)
500+
479501
## Source compatibility
480502

481503
This change is purely additive; it only affects the behavior of code which uses

0 commit comments

Comments
 (0)