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

Comments

Projects
None yet
3 participants
@dimenus
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

This comment has been minimized.

Member

andrewrk commented Nov 22, 2017

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

@andrewrk andrewrk changed the title from Return type of '@sizeOf' does not feel ergonomic to allow integer literals to be passed to var args parameters and parameters of type `var` 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 modified the milestones: 0.4.0, 0.3.0 Apr 11, 2018

@andrewrk andrewrk closed this in e48e707 Apr 11, 2018

@thejoshwolfe

This comment has been minimized.

Member

thejoshwolfe commented Apr 12, 2018

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

@andrewrk

This comment has been minimized.

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