Skip to content

@field builtin function to do field access with a comptime string as the field name #766

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

Closed
Hejsil opened this issue Feb 9, 2018 · 1 comment · Fixed by #934
Closed
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@Hejsil
Copy link
Contributor

Hejsil commented Feb 9, 2018

Add following builtin function:

@memberTag(comptime T: type, index: usize) -> (error set or enum value from T)

Example of how it works:

@memberTag(enum { A, B, C }, 1) // returns B
@memberTag(error { D, E, F }, 1) // returns E

Idk what the use case is for having it work for enums, but the use case for error sets was mentioned here.

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. accepted This proposal is planned. labels Feb 9, 2018
@andrewrk andrewrk added this to the 0.2.0 milestone Feb 9, 2018
@andrewrk
Copy link
Member

andrewrk commented Feb 9, 2018

Now that I think of it, I think this is accomplished by:

@field(T, @memberName(T, index))

So I'll implement @field instead.

@andrewrk andrewrk changed the title Have buildin function for getting the tag value of enums and error sets. @field builtin function to do field access with a comptime string as the field name Feb 11, 2018
@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Feb 11, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.3.0 Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants