I am working on a small library and I’m trying to do something similar to this where I have this one super class that a bunch of other classes are going to inherit from
abstract class Animal abstract def speak(sound : String) end class Cat < Animal def speak(sound : String) sound end end animals : Array(Animal) = [Cat.new]
I would expect this to work because
Cat inherits from
Animal and therefore is an
Animal (?) but for some reason this is not allowed?
Showing last frame. Use --error-trace for full trace. error in line 11 Error: type must be Array(Animal), not Array(Cat)