Skip to content

Error message when trying to loop over tuple without inline is confusing #26022

@Justus2308

Description

@Justus2308

Zig Version

0.15.2

Steps to Reproduce and Observed Output

When trying to loop over a tuple with runtime-known fields without inline:

pub fn main() !void {
    var tuple = .{ @as(u32, 123), @as(u32, 456) };
    _ = &tuple;
    for (tuple) |value| _ = value;
}
./example.zig:4:10: error: unable to resolve comptime value
    for (tuple) |value| _ = value;
         ^~~~~
./example.zig:4:10: note: tuple field index must be comptime-known

This requires quite a mental jump and knowledge of how tuples are represented to figure out that inline is the solution here. Making the 'tuple field index' comptime-known is a concept that shouldn't really be exposed to the user if they're not explicitly using @typeInfo IMO.

Expected Output

An error message that is more context-aware and directly suggests using inline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions