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

ability to iterate over a tuple with an inline for loop, when the tuple has runtime fields in it #280

Closed
andrewrk opened this issue Mar 23, 2017 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@andrewrk
Copy link
Member

See #77

@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Mar 23, 2017
@andrewrk andrewrk modified the milestone: 0.2.0 Mar 26, 2017
@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Jan 3, 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
@hryx
Copy link
Contributor

hryx commented Jul 8, 2019

Shouldn't this be closed because of #208 ? Once that's done, one can iterate over a "var args" struct parameter with meta.fields() right?

Edit: as @daurnimator points out, there is still C varargs to worry about.

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 21, 2019
@andrewrk
Copy link
Member Author

andrewrk commented Dec 9, 2019

This works:

const std = @import("std");
test "aoeu" {
    var tuple = .{1, 2};
    inline for (tuple) |x| {
        std.debug.warn("{}\n", .{x});
    }
}

however this should work but does not:

const std = @import("std");
test "aoeu" {
    var runtime_two: i32 = 2;
    var tuple = .{1, runtime_two};
    inline for (tuple) |x| {
        std.debug.warn("{}\n", .{x});
    }
}

gives

/home/andy/Downloads/zig/build/test.zig:5:25: error: cannot store runtime value in compile time variable
    inline for (tuple) |x| {
                        ^

Zig needs to not make x a comptime variable when iterating over a tuple. In fact it is a value that will sometimes be comptime, sometimes not.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Dec 9, 2019
@andrewrk andrewrk changed the title support iterating over var args value with a for loop ability to iterate over a tuple with an inline for loop, when the tuple has runtime fields in it Dec 9, 2019
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 9, 2020
daurnimator added a commit to daurnimator/zig that referenced this issue Nov 4, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@nektro
Copy link
Contributor

nektro commented Mar 7, 2023

fixing the snippet to use std.log.debug makes this work now

@Vexu Vexu closed this as completed Mar 7, 2023
@Vexu Vexu modified the milestones: 0.13.0, 0.11.0 Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
Development

No branches or pull requests

4 participants