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 modify the elements of a tuple in an inline for loop #14705

Closed
verdog opened this issue Feb 22, 2023 · 0 comments · Fixed by #15983
Closed

Unable to modify the elements of a tuple in an inline for loop #14705

verdog opened this issue Feb 22, 2023 · 0 comments · Fixed by #15983
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@verdog
Copy link
Contributor

verdog commented Feb 22, 2023

Zig Version

0.11.0-dev.1711+dc1f50e50

Steps to Reproduce and Observed Behavior

In zig 0.10.1 (last stable release) this works:

const std = @import("std");

test "iterate and modify a tuple" {
    var tuple: std.meta.Tuple(&[_]type{ usize, usize, usize, usize, usize }) = undefined;
    inline for (tuple) |*elem| {
        elem.* = 101;
    }

    std.debug.print("{any}\n", .{tuple});
}
Test [1/1] test.iterate and modify a tuple... { 101, 101, 101, 101, 101 }
All 1 tests passed.

But in zig 0.11.0-dev.1711+dc1f50e50, it seems to be impossible (starting with same source as above):

const std = @import("std");

test "iterate and modify a tuple" {
    var tuple: std.meta.Tuple(&[_]type{ usize, usize, usize, usize, usize }) = undefined;
    inline for (tuple) |*elem| {
        elem.* = 101;
    }

    std.debug.print("{any}\n", .{tuple});
}
repro.zig:5:25: error: pointer capture of non pointer type 'meta.CreateUniqueTuple(5,.{ usize, usize, usize, usize, usize })'
    inline for (tuple) |*elem| {
                        ^~~~~~

And the new & syntax gives me:

const std = @import("std");

test "iterate and modify a tuple" {
    var tuple: std.meta.Tuple(&[_]type{ usize, usize, usize, usize, usize }) = undefined;
    inline for (&tuple) |*elem| {
        elem.* = 101;
    }

    std.debug.print("{any}\n", .{tuple});
}
repro.zig:5:17: error: type '*meta.CreateUniqueTuple(5,.{ usize, usize, usize, usize, usize })' does not support indexing
    inline for (&tuple) |*elem| {
                ^~~~~~
repro.zig:5:17: note: for loop operand must be an array, slice, tuple, or vector

Expected Behavior

There should be some way to iterate over a tuple and pointer capture its elements.


This is similar to #13852 but I thought it was just unique enough for a new issue.

@verdog verdog added the bug Observed behavior contradicts documented or intended behavior label Feb 22, 2023
@andrewrk andrewrk added this to the 0.12.0 milestone Apr 10, 2023
mlugg added a commit to mlugg/zig that referenced this issue Jun 9, 2023
mlugg added a commit to mlugg/zig that referenced this issue Jun 14, 2023
mlugg added a commit to mlugg/zig that referenced this issue Jun 14, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jun 14, 2023
andrewrk pushed a commit that referenced this issue Jun 15, 2023
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
Techatrix added a commit to zigtools/zls that referenced this issue Nov 17, 2023
- fix data race when allocating with thread safety
- remove workarounds for ziglang/zig#14705
- correct unnecessary uses of 'var'

Note that the BSD Zero Clause License has been removed
from binned_allocator.zig
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

Successfully merging a pull request may close this issue.

2 participants