The Crystal Programming Language Forum

Compilation Error: Generic class with instance var of array of class type with generic parameter

I get a compilation error with this code:

class Cmd(C)
end

class Adm < Cmd(Int32)
end

class Ns(C)
  getter cmds : Array(Cmd(C).class) = Array(Cmd(C).class).new
end

ns = Ns(Int32).new

See: Carcin

Error:

instance variable '@cmds' of Ns(Int32) must be Array(Cmd(C).class), not Array(Cmd(Int32).class)

If i change the array type by removing “.class”, then it compiles. I am unsure about what is wrong with this.

I am not sure what is going out but if you remove Adm then your code compiles :thinking:

Please report a bug. Thank you!

Done: Compilation Error: Generic class with instance var of array of class type with generic parameter · Issue #10691 · crystal-lang/crystal · GitHub