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

unable to call var args function at compile time #313

Closed
andrewrk opened this issue Apr 7, 2017 · 3 comments
Closed

unable to call var args function at compile time #313

andrewrk opened this issue Apr 7, 2017 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Apr 7, 2017

test "runtime parameter before var args" {
    comptime {
        assert(extraFn(10) == 0);
        assert(extraFn(10, false) == 1);
        assert(extraFn(10, false, true) == 2);
    }
}

fn extraFn(extra: u32, args: ...) -> usize {
    if (args.len >= 1) {
        assert(args[0] == false);
    }
    if (args.len >= 2) {
        assert(args[1] == true);
    }
    return args.len;
}
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Apr 7, 2017
@andrewrk andrewrk added this to the 0.1.0 milestone Apr 7, 2017
@andrewrk andrewrk modified the milestones: 0.2.0, 0.1.0 Apr 21, 2017
@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Jan 19, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Feb 4, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 21, 2019
@japplegame
Copy link

How difficult is it to fix this?

@emekoi
Copy link
Contributor

emekoi commented Nov 3, 2019

this is being fixed by #208, which removes zig var args in favor of anonymous lists.

@andrewrk
Copy link
Member Author

andrewrk commented Dec 9, 2019

Here's what this looks like with tuples:

const std = @import("std");
const assert = std.debug.assert;

test "runtime parameter before var args" {
    comptime {
        assert(extraFn(10, .{}) == 0);
        assert(extraFn(10, .{false}) == 1);
        assert(extraFn(10, .{ false, true }) == 2);
    }
}

fn extraFn(extra: u32, args: var) usize {
    if (args.len >= 1) {
        assert(args[0] == false);
    }
    if (args.len >= 2) {
        assert(args[1] == true);
    }
    return args.len;
}
$ ./zig test test.zig 
All 1 tests passed.

var args removed from the language in a3f6a58

@andrewrk andrewrk closed this as completed Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants