[swift-evolution] Allow protocol vars to match derived types

Joe Groff jgroff at apple.com
Tue Mar 8 15:27:55 CST 2016


> On Mar 8, 2016, at 1:15 PM, Mark Anders via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Slava/Joe, thanks for clarifying the issue and Slava for providing more depth on what needs to happen. Like David, I was unsure if this was just a bug or an enhancement.
> 
> Out of curiosity, you mention some related issues, and I just ran into something similar and wonder if it’s related too.
> 
> class A {}
> class B : A {}
> 
> var arrayOfA = [A]()
> let arrayOfB : [B] = [B()]
> arrayOfA.appendContentsOf(arrayOfB)
> 
> This fails to compile, though doing arrayOfA.append(B()) works as I would expect.

This one seems like a plain bug to me, since it should be possible to convert arrayOfB to [A] and hand the [A] off to appendContentsOf.

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160308/2b9ef286/attachment.html>


More information about the swift-evolution mailing list