You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
conststd=@import("std");
test"broken" {
constI=struct {
// Adding a field or making `self` a non-pointer fixes the errorfnnext(_: *@This()) i32 {
return2;
}
};
variters: struct { I, I } = .{ I{}, I{} };
//@compileError(@typeName(@TypeOf(iters)));varresult: struct { i32, i32 } =undefined;
result[0] =iters[0].next(); // error: runtime value contains reference to comptime varresult[1] =iters[1].next();
trystd.testing.expectEqual(result, .{ 2, 2 });
}
I get a compilation error. I find this very confusing as it refers to a "comptime var" when I have not used "comptime" anywhere in the code.
src/main.zig:38:25: error: runtime value contains reference to comptime var
result[0] = iters[0].next(); // error: runtime value contains reference to comptime var
~~~~~~~~^~~~~
src/main.zig:38:25: note: comptime var pointers are not available at runtime
Printing the type of iters reveals that iters apparently has two comptime fields.
tomboehmer
changed the title
Zero size tuple field is implicitly comptime which leads confusing error message
Zero size tuple field is implicitly comptime which leads to confusing error message
Dec 26, 2024
Zig Version
0.14.0-dev.2563+af5e73172
Steps to Reproduce and Observed Behavior
I get a compilation error. I find this very confusing as it refers to a "comptime var" when I have not used "comptime" anywhere in the code.
Printing the type of
iters
reveals thatiters
apparently has two comptime fields.Expected Behavior
There are two behaviors i would think sensible.
Talking about a "comptime var" when there is no "comptime" in the code is not helpful.
Actually, I think option 1 should be correct, because the following also compiles:
The text was updated successfully, but these errors were encountered: