Search code examples
crystal-lang

Why Object can't be type of argument for Proc object


I have such code:

p = ->(x : Object) { x }
puts p.call(3)

and when I compile it I receive such exception:

cannot be used as a Proc argument type yet, use a more specific type

could someone explain me why is this, for what reason Proc cannot be parametrised by Object?


Solution

  • It says "yet". That will be probably supported in the future ;-)

    The main reason is that Object means anything, including objects passed by value, with different sizes. That means the compiler has to allocate enough space for any type, or, more factible, automatically box and unbox value types. This latest approach might be implemented in a future version of the compiler.