-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed as duplicate of#63877
Closed as duplicate of#63877
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.parameterized protocolsFeature → protocol: protocols with primary associated typesFeature → protocol: protocols with primary associated typesprotocol compositionsFeature → types: protocol composition typesFeature → types: protocol composition typesswift 6.2triage neededThis issue needs more specific labelsThis issue needs more specific labelsunexpected errorBug: Unexpected errorBug: Unexpected error
Description
Description
I wanted to write the type any Foo<Int> & Bar
, where Foo
is a protocol with a primary associated type and Bar
is another protocol. For some reason the compiler disallows this with any
but allows it with some
.
For example, this function is okay:
doSomething(_: some Foo<Int> & Bar) {}
But this isn't
doSomething(_: any Foo<Int> & Bar) {}
// Error: non-protocol, non-class type 'Foo<Int>' cannot be used within a protocol-constrained type
Similarly:
// Works
typealias Baz = Foo<Int> & Bar
// Neither of these work
let _: any Foo<Int> & Bar
let _: any (Foo<Int> & Bar)
// Works
let _: any Baz
Reproduction
protocol Foo<T> {
associatedtype T
}
protocol Bar {}
func doSomething(_: some Foo<Int> & Bar) {}
func doSomething(_: any Foo<Int> & Bar) {} // Error: non-protocol, non-class type 'Foo<Int>' cannot be used within a protocol-constrained type
Expected behavior
Expect that any
and some
are supported equally when it comes to the constraints they are attached to, and more specifically that any Foo<Int> & Bar
is allowed.
Environment
Swift version 6.2-dev (LLVM 978186dad468cc4, Swift 2d7b7a7)
Target: x86_64-unknown-linux-gnu
Additional information
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.parameterized protocolsFeature → protocol: protocols with primary associated typesFeature → protocol: protocols with primary associated typesprotocol compositionsFeature → types: protocol composition typesFeature → types: protocol composition typesswift 6.2triage neededThis issue needs more specific labelsThis issue needs more specific labelsunexpected errorBug: Unexpected errorBug: Unexpected error