[swift-users] Initializer inheritance doesn't work with generic class?
Neil Faiman
neil.swift at faiman.org
Sun May 15 14:09:47 CDT 2016
This compiles fine:
class Sup {
init(supDes: Int) {}
convenience init(supCon: Int) { self.init(supDes: supCon) }
}
class Sub : Sup {
convenience init(subCon1: Int) { self.init(supDes: subCon1) }
convenience init(subCon2: Int) { self.init(supCon: subCon2) }
}
But if I make the classes generic:
class Sup<T> {
init(supDes: T) {}
convenience init(supCon: T) { self.init(supDes: supCon) }
}
class Sub<T> : Sup<T> {
convenience init(subCon1: T) { self.init(supDes: subCon1) }
convenience init(subCon2: T) { self.init(supCon: subCon2) }
}
the compiler is doesn’t like it:
error: argument labels '(supDes:)' do not match any available overloads
convenience init(subCon1: T) { self.init(supDes: subCon1) }
^ ~~~~~~~~~~~~~~~~~
note: overloads for 'Sub<T>.init' exist with these partially matching parameter lists: (subCon1: T), (subCon2: T)
convenience init(subCon1: T) { self.init(supDes: subCon1) }
^
error: argument labels '(supCon:)' do not match any available overloads
convenience init(subCon2: T) { self.init(supCon: subCon2) }
^ ~~~~~~~~~~~~~~~~~
note: overloads for 'Sub<T>.init' exist with these partially matching parameter lists: (subCon1: T), (subCon2: T)
convenience init(subCon2: T) { self.init(supCon: subCon2) }
^
Expected behavior? Implementation limitation? Bug?
Thanks,
Neil Faiman
More information about the swift-users
mailing list