I think the problem is T isn’t known in the class scope, only in the instance scope when instantiated. Workaround would be like add some abstract non-generic class and inherit from that. Then type the array using that abstract parent type.
Yes, it works! Thanks a lot @Blacksmoke16 !
Here is the modified code:
abstract class ATest
class_property instances = [] of ATest
end
class Test(T) < ATest
def initialize(@var : T)
ATest.instances << self
end
end
x = Test.new(33)
y = Test.new("abc")
p! ATest.instances