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 integer literals to be passed to var args parameters and parameters of type var #623

Closed
dimenus opened this issue Nov 22, 2017 · 3 comments
Labels
accepted This proposal is planned. enhancement Solving this issue will likely involve adding new logic or components to the codebase. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@dimenus
Copy link
Contributor

dimenus commented Nov 22, 2017

consider the following zig code:

const std = @import("std");
const debug = std.debug;
const MyEnum = enum {
    Zero,
    One,
    Two,
    Three,
};
pub fn main() -> %void {
    debug.warn("{}\n", @sizeOf(MyEnum));
}

fails with:
error: parameter of type '(integer literal)' requires comptime

It would feel much better if 'sizeOf' was defined to either return a u32 or would automatically coerce into the appropriate type rather than having to cast it.

@andrewrk
Copy link
Member

More generally, we should allow integer literals to be passed to a parameter of type var. This is planned.

@andrewrk andrewrk changed the title Return type of '@sizeOf' does not feel ergonomic allow integer literals to be passed to var args parameters and parameters of type var Nov 22, 2017
@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Nov 22, 2017
@andrewrk andrewrk added this to the 0.3.0 milestone Nov 22, 2017
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@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 Apr 11, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.3.0 Apr 11, 2018
@thejoshwolfe
Copy link
Sponsor Contributor

How does this work? is the function instantiated for every different literal value?

@andrewrk
Copy link
Member

andrewrk commented Apr 12, 2018

That's correct. Also it still doesn't work with var args because of #557. I'm considering fixing it by replacing var args with a tuple type (see #533). Someone on IRC also suggested that tuple types could be implemented in userland if we had @reflect and @reify (See #383).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. enhancement Solving this issue will likely involve adding new logic or components to the codebase. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants