-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
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.
paoda
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior