Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using Object and similar types as instance variable types #2733

Open
asterite opened this issue Jun 3, 2016 · 8 comments
Open

Allow using Object and similar types as instance variable types #2733

asterite opened this issue Jun 3, 2016 · 8 comments

Comments

@asterite
Copy link
Member

asterite commented Jun 3, 2016

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.

@lbguilherme
Copy link
Contributor

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.

@asterite
Copy link
Member Author

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

@asterite
Copy link
Member Author

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.

@lbguilherme
Copy link
Contributor

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.

@KCreate
Copy link
Contributor

KCreate commented Aug 22, 2016

Hello

What priority does this issue have right now?

@zatherz
Copy link
Contributor

zatherz commented Nov 25, 2017

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

@zatherz
Copy link
Contributor

zatherz commented May 28, 2018

Reason for closing?

@HertzDevil
Copy link
Contributor

I just had this idea:

module ValueM; end
module ReferenceM; end

struct Value
  include ValueM
end

class Reference
  include ReferenceM
end

alias Any = ValueM | ReferenceM

Of course, doing it this way means Any must be bigger than the biggest Value type ever instantiated, which is UInt8[4096] for the standard library.

For Reference and Class this should be doable. (You can in fact already do Reference.new, you just can't cast to it explicitly.) For uninstantiated generics this is more tricky; what should the type below be?

typeof([1].as(Indexable)[0])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants