[swift-users] Still can't derive from a generic class

Jon Shier jon at jonshier.com
Tue Aug 29 12:20:03 CDT 2017


This works fine for me in a playground in the latest Xcode 9 beta:

class Test { }

class Base<T: AnyObject> { }

class Sub: Base<Test> { }

let sub = Sub()



Jon


> On Aug 29, 2017, at 1:04 PM, Joanna Carter via swift-users <swift-users at swift.org> wrote:
> 
> Hi
> 
> I would have hoped by now that it should be possible to do :
> 
> class BaseObject<rootType : AnyObject>
> {
> }
> 
> class Test : BaseObject<Test>
> {
> }
> 
> All compiles well but, at runtime, when calling let test = Test(), I get a "EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" error.
> 
> This is something I have been able to do in C# for many a year. Why oh why can I still not do it in Swift ?
> 
> Joanna
> 
> --
> Joanna Carter
> Carter Consulting
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list