Multiple Class Types in Protocol Composition

Hi everyone,

I noticed strange behaviour of the Swift 4.0.3 compiler regarding class and subtype existentials.

According to the proposal SE-0156 (https://github.com/apple/swift-evolution/blob/master/proposals/0156-subclass-existentials.md\), multiple class types in protocol compositions should be allowed, if:

  * The class types are the same
  * Or, one class type must be a subtype of the other.

However, when copying the exact code from the proposal into Xcode 9.2, the result is the following:

My conclusion here is that the compiler does not allow multiple class types in one protocol composition.

My question is:
Is this behaviour intended or should I open a bug report?

Thank you very much

BR
Mario

Hi Mario,

You’re right that this part of the proposal was not fully implemented. Computing the common ancestor of two superclasses is a little tricky here because it would force us to resolve the superclass type of a class when realizing a subclass existential. This would introduce circular dependencies. Either I missed something obvious or it would require some re-architecting of the type checker to make it work.

Either way, yes it’s a known limitation, but not one that is tracked by a JIRA presently, so please do file a bug!

Thanks,

Slava

···

On Dec 7, 2017, at 7:17 AM, Mario Meili via swift-users <swift-users@swift.org> wrote:

Hi everyone,

I noticed strange behaviour of the Swift 4.0.3 compiler regarding class and subtype existentials.

According to the proposal SE-0156 (https://github.com/apple/swift-evolution/blob/master/proposals/0156-subclass-existentials.md\), multiple class types in protocol compositions should be allowed, if:

The class types are the same
Or, one class type must be a subtype of the other.

However, when copying the exact code from the proposal into Xcode 9.2, the result is the following:

<image001.png>

My conclusion here is that the compiler does not allow multiple class types in one protocol composition.

My question is:
Is this behaviour intended or should I open a bug report?

Thank you very much

BR
Mario
_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

Hi Slava,

Thank you very much for the quick response. As you requested, I filed the bug under the following link: [SR-6561] Multiple Class Types in Protocol Composition not implemented · Issue #49111 · apple/swift · GitHub

Best Regards
Mario

···

From: <spestov@apple.com> on behalf of Slava Pestov <spestov@apple.com>
Date: Thursday, 7 December 2017 at 22:27
To: Mario Meili <mario.meili@live.com>
Cc: "swift-users@swift.org" <swift-users@swift.org>
Subject: Re: [swift-users] Multiple Class Types in Protocol Composition

Hi Mario,

You’re right that this part of the proposal was not fully implemented. Computing the common ancestor of two superclasses is a little tricky here because it would force us to resolve the superclass type of a class when realizing a subclass existential. This would introduce circular dependencies. Either I missed something obvious or it would require some re-architecting of the type checker to make it work.

Either way, yes it’s a known limitation, but not one that is tracked by a JIRA presently, so please do file a bug!

Thanks,

Slava

On Dec 7, 2017, at 7:17 AM, Mario Meili via swift-users <swift-users@swift.org<mailto:swift-users@swift.org>> wrote:

Hi everyone,

I noticed strange behaviour of the Swift 4.0.3 compiler regarding class and subtype existentials.

According to the proposal SE-0156 (https://github.com/apple/swift-evolution/blob/master/proposals/0156-subclass-existentials.md&lt;https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fapple%2Fswift-evolution%2Fblob%2Fmaster%2Fproposals%2F0156-subclass-existentials.md&data=02|01||f12145f448334d2a644c08d53db941d1|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|636482788230444913&sdata=bjKRAVds%2BubJz5Mpi27bQmpbBigAfekf%2FiXopHekabE%3D&reserved=0&gt;\), multiple class types in protocol compositions should be allowed, if:

  * The class types are the same
  * Or, one class type must be a subtype of the other.

However, when copying the exact code from the proposal into Xcode 9.2, the result is the following:

<image001.png>

My conclusion here is that the compiler does not allow multiple class types in one protocol composition.

My question is:
Is this behaviour intended or should I open a bug report?

Thank you very much

BR
Mario
_______________________________________________
swift-users mailing list
swift-users@swift.org<mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users&lt;https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.swift.org%2Fmailman%2Flistinfo%2Fswift-users&data=02|01||f12145f448334d2a644c08d53db941d1|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|636482788230444913&sdata=pY7NkpjW9jmvnhjXYa3axI%2F631OaDOdJ0F4KsIb%2FXHI%3D&reserved=0&gt;