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

Instance creation failure when enum property types encountered #90

Open
eldcn opened this issue Jun 2, 2021 · 1 comment
Open

Instance creation failure when enum property types encountered #90

eldcn opened this issue Jun 2, 2021 · 1 comment

Comments

@eldcn
Copy link

eldcn commented Jun 2, 2021

Hey, first of all kudos for the great job with the library.

I do have a question regarding createInstance(of:constructor:) api. It is currently building struct and class kinds. Is there any technical reason why instance creation for enum is not supported, at least for ones with String or Int as RawValue type? Since the method performs recursive calls on the properties, it fails once a nested enum property is encountered. Are there any plans in the near future to also support instance creation for enums, if this is technically possible of course?

@wickwirew
Copy link
Owner

Its definitely possible. The RawValue actually really doesn't matter and is not stored inline in the enum. So any enum that doesn't have a case with a payload will always be just 1 byte. Which means initializing one is as simple as figuring out the case index and bit casting it as a UInt8 to the enum type.

It gets tricky with cases that have payloads. They are laid out with the payload first, then the case index (most of the time). Single case enums will omit the case part since there is only ever one possible case. Runtime at the moment doesn't get all of the necessary metadata needed to properly initialize one.

I can try to take a look, but if I'm being honest Im pretty busy currently and don't really have a lot of time to look into it.

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

No branches or pull requests

2 participants