Avatar
omochimetaru 9/10/2018 2:50 AM
// $ swift -swift-version 5 protocol CopyInitializable { init(copy: Self) } extension CopyInitializable { init(copy: Self) { self = copy } } class Animal : CopyInitializable { convenience init(animal: Animal) { self.init(copy: animal) } }
2:50 AM
a.swift:13:25: error: cannot convert value of type 'Animal' to expected argument type 'Self' self.init(copy: animal) ^~~~~~ as! Self
2:51 AM
> おかしいのは、ここで self.init(_with: ) が呼び出せてしまうことじゃないですか? > AnimalProtocolが引数に受けてる Self は、 AnimalBase が final で無いのだから > 何かのサブクラスである可能性があって (たとえばCat ) > なのに、 obj: AnimalBase を渡せてしまっている
2:51 AM
自分の考えと一致する方向で修正されている〜
🙌 1