Home > OS >  Why recursively-bound inheritance is not allowed in Swift
Why recursively-bound inheritance is not allowed in Swift

Time:12-25

I am trying to create a base class as follows:

open class ManagedObject<Entity: NSManagedObject>: NSManagedObject{
    
}

then use it as:

class LocalEntity: ManagedObject<LocalEntity>{
    
}

And it gives me an error:

'LocalEntity' inherits from itself

'ManagedObject' requires that 'LocalEntity' inherit from 'NSManagedObject'

I do not really get why I am getting such error. This looks totally valid inheritance case. I would be happy if anyone would give me a source to read or explain why it is not allowed to do this.

CodePudding user response:

This is just a compiler bug. If you have a practical use for it, I recommend commenting on the issue.

  • Related