Crystal: Allow using `Object` and similar types as instance variable types

Created on 3 Jun 2016  路  7Comments  路  Source: crystal-lang/crystal

Object, Reference, Enum, Enumerable and many other types that are currently disallowed should be able to be used as the type of instance, class and global variables.

This is a current limitation of the language but it's doable. It will come with time.

feature compiler

All 7 comments

struct Foo
  @thing : Object
end

Object is a superclass of any struct. That mean @thing can contain any struct or the program. So sizeof(@thing) is the size of the largest struct known plus 4 bytes for the type id. Does that mean @thing can contain Foo itself? It gets cyclic.

Objects larger than 64 bits will be boxed in heap memory.

Mmm... but for that case, I'm not sure. Object wlll be represented as a 64 bits raw pointer... I guess that can be codegen'd, not sure. Maybe it'll be an error.

I can be unexpected that some times it is copied by value and some others it is copied by reference (boxed). Maybe it could be always boxed when the type is Object.

Hello

What priority does this issue have right now?

Bump. IMO the value should always be boxed when passed as Object, so that there's less magic and unpredictability.

Reason for closing?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xtagon picture xtagon  路  132Comments

benoist picture benoist  路  59Comments

sergey-kucher picture sergey-kucher  路  66Comments

stugol picture stugol  路  70Comments

farleyknight picture farleyknight  路  64Comments