mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
In code like the following:
```
protocol P { associatedtype A: Hashable }
protocol Q { associatedtype A: Comparable }
func fn<T: P & Q>(_: T) where T.A == Int { … }
```
`T.A` is actually the union of `P.A` and `Q.A`—it satisfies both associated types and has both of their constraints. This means it doesn’t actually make sense to apply a module selector to `A`—even if `P` and `Q` are in different modules, `T.A` always represents both of the declarations, not one or the other. We therefore now ban module selectors in this position, since they don’t actually jibe with the nature of a generic signature.
This justification technically doesn’t hold for *every* member type of a generic parameter—a member type can refer to a concrete typealias in a protocol extension, for instance—but in those situations, you can disambiguate (and add module selectors) by writing `P.A` or `Q.A` instead of `T.A`, so we’re not really worried about this limitation.
51 lines
1.1 KiB
Plaintext
51 lines
1.1 KiB
Plaintext
// swift-interface-format-version: 1.0
|
|
// swift-module-flags: -module-name ModuleSelectorTestingKit -swift-version 5
|
|
|
|
import Swift
|
|
|
|
// These types are identical; we just use them to test with different scope
|
|
// selectors.
|
|
|
|
public struct A {
|
|
public init(value: Swift.Int)
|
|
public dynamic mutating func negate()
|
|
public var magnitude: Swift.UInt
|
|
}
|
|
|
|
public struct B {
|
|
public init(value: Swift.Int)
|
|
public dynamic mutating func negate()
|
|
public var magnitude: Swift.UInt
|
|
}
|
|
|
|
public struct C {
|
|
public init(value: Int)
|
|
public dynamic mutating func negate()
|
|
public var magnitude: Swift.UInt
|
|
}
|
|
|
|
public struct D {
|
|
public init(value: Int)
|
|
public dynamic mutating func negate()
|
|
public var magnitude: Swift.UInt
|
|
}
|
|
|
|
@propertyWrapper
|
|
public struct available {
|
|
public init() {}
|
|
public var wrappedValue: Int { 0 }
|
|
}
|
|
|
|
@_functionBuilder
|
|
public struct MyBuilder {
|
|
public static func buildBlock()
|
|
}
|
|
|
|
public protocol ComparableIdentifiable {
|
|
associatedtype ID: Comparable
|
|
var id: ID { get }
|
|
}
|
|
|
|
@freestanding(expression) public macro ExprMacro() -> String = #file
|
|
@attached(peer) public macro PeerMacro() = #externalMacro(module: "Fnord", type: "PeerMacro")
|