Extensions on Typealiased Existential Protocols

Is this error intentional, or a bug?

protocol A {}

protocol B {}

typealias C = A & B // valid

extension C {} // Error: Non-nominal type 'C' (aka 'A & B') cannot be
extended

extension A where Self: B {} // valid

struct Foo: C {} // valid

Since extension A where Self: B is the same as extension B where Self: A,
and C is defined as any A that also inherits from B, shouldn’t extension C be
just as valid?

This seems like it should be valid, so I filed this bug,
https://bugs.swift.org/browse/SR-5260\.

- Steve

Hi Steven,

Is this error intentional, or a bug?

It’s intentional. We could add support for this as an extra bit of sugar, but note that

Since extension A where Self: B is the same as extension B where Self: A,

This is not quite true.

Slava

···

On Jun 19, 2017, at 11:44 AM, Steven Brunwasser via swift-users <swift-users@swift.org> wrote:

What I usually do here is:
typealias CProtocol = A & B
protocol C: CProtocol { } // or just A & B directly, I think
extension C {}

So it’s a bit silly to me.

Jon

···

On Jun 19, 2017, at 3:44 PM, Slava Pestov via swift-users <swift-users@swift.org> wrote:

Hi Steven,

On Jun 19, 2017, at 11:44 AM, Steven Brunwasser via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:

Is this error intentional, or a bug?

It’s intentional. We could add support for this as an extra bit of sugar, but note that

Since extension A where Self: B is the same as extension B where Self: A,

This is not quite true.

Slava

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

IIUC (which shouldn't be assumed on your part) the difference is that any types which conform to both `A` and `B` will automatically conform to `CProtocol` as well, but not `C`. I suspect the "automatic conformance" bit is why we don't currently allow it.

- Dave Sweeris

···

On Jun 19, 2017, at 13:44, Jon Shier via swift-users <swift-users@swift.org> wrote:

What I usually do here is:
typealias CProtocol = A & B
protocol C: CProtocol { } // or just A & B directly, I think
extension C {}

So it’s a bit silly to me.

Jon

On Jun 19, 2017, at 3:44 PM, Slava Pestov via swift-users <swift-users@swift.org> wrote:

Hi Steven,

On Jun 19, 2017, at 11:44 AM, Steven Brunwasser via swift-users <swift-users@swift.org> wrote:

Is this error intentional, or a bug?

It’s intentional. We could add support for this as an extra bit of sugar, but note that

Since extension A where Self: B is the same as extension B where Self: A,

This is not quite true.

Slava

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

@David But the automatic conformance is currently supported through
extension A where Self: B.

@Slava When does extension A where Self: B not equal extension B where Self:
A? Why would protocol inheritance not be communicative?

···

On June 19, 2017 at 5:26:44 PM, David Sweeris (davesweeris@mac.com) wrote:

IIUC (which shouldn't be assumed on your part) the difference is that any
types which conform to both `A` and `B` will *automatically* conform to
`CProtocol` as well, but not `C`. I suspect the "automatic conformance" bit
is why we don't currently allow it.

- Dave Sweeris

On Jun 19, 2017, at 13:44, Jon Shier via swift-users <swift-users@swift.org> wrote:

What I usually do here is:
typealias CProtocol = A & B
protocol C: CProtocol { } // or just A & B directly, I think
extension C {}

So it’s a bit silly to me.

Jon

On Jun 19, 2017, at 3:44 PM, Slava Pestov via swift-users < swift-users@swift.org> wrote:

Hi Steven,

On Jun 19, 2017, at 11:44 AM, Steven Brunwasser via swift-users < swift-users@swift.org> wrote:

Is this error intentional, or a bug?

It’s intentional. We could add support for this as an extra bit of sugar,
but note that

Since extension A where Self: B is the same as extension B where Self: A,

This is not quite true.

Slava

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users