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.
I'd expect the following program to never hit the "invalid field type" @compileError in the typeinfo switch. This particular @compileError is conditioned under if (!isIdField(...)) but the if-body runs regardless of what isIdField function returns.
Here's the program:
conststd=@import("std");
pubfnOuter(comptimeComponents: []consttype) type {
returnstruct {
fncompTagBits(comptimeC: type) u32 {
inlinefor (Components, 0..) |c, i| {
if (c==C) {
return1<<i;
}
}
@compileError("unhandled component type "++@typeName(C));
}
fnisIdField(comptimefield: std.builtin.Type.StructField) bool {
_=field;
// compileError happens regardless of what this function returnsreturntrue;
}
fncompTagBitsStruct(comptimeC: type) u32 {
if (@typeInfo(C) !=.Struct) {
@compileError("Expecting struct type, got "++@typeName(C));
}
varmask: u32=0;
constfields=std.meta.fields(C);
inlinefor (fields) |field| {
switch (@typeInfo(field.type)) {
.Optional=> {}, // do nothing for optional fields.Pointer=>|info| {
mask|=compTagBits(info.child);
}, // required componentelse=> {
if (!isIdField(field)) {
// NOTE why do we hit this @compileError when isIdField is// hardcoded to return true? Replacing isIdField(field)// with literal "false" doesn't hit this path.@compileError("invalid field type "++field.name++":"++@typeName(field.type));
}
},
}
}
returnmask;
}
};
}
test"weird behavior" {
constPos=struct { p: @Vector(2, f32) };
constVelocity=struct { v: @Vector(2, f32) };
constRet=struct {
id: u32,
p: *Pos,
v: *Velocity,
};
constO=Outer(&[_]type{ Pos, Velocity });
constbits=O.compTagBitsStruct(Ret);
std.debug.print("bits {b}\n", .{bits});
}
Saving this into file repro.zig and running zig test src\repro.zig, I get the below unexpected error message:
src\repro.zig:37:29: error: invalid field type id:u32
@compileError("invalid field type " ++ field.name ++ ":" ++ @typeName(field.type));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
test.weird behavior: src\repro.zig:56:19
remaining reference traces hidden; use '-freference-trace' to see all reference traces
Expected Behavior
I'd expect this if-body to be never taken:
if (!isIdField(field)) {
// NOTE why do we hit this @compileError when isIdField is
// hardcoded to return true? Replacing isIdField(field)
// with literal "false" doesn't hit this path.
@compileError("invalid field type " ++ field.name ++ ":" ++ @typeName(field.type));
}
This is an extract from a bigger program, the contents of isIdField were originally more complicated until I noticed that it doesn't really matter what it returns.
I noticed #15122 and this bug kind of has a similar energy.
The text was updated successfully, but these errors were encountered:
nurpax
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Mar 31, 2023
Zig Version
0.11.0-dev.1893+277015960
(Windows 10, 64-bit, default zig build options)
Steps to Reproduce and Observed Behavior
I'd expect the following program to never hit the "invalid field type"
@compileErrorin the typeinfo switch. This particular@compileErroris conditioned underif (!isIdField(...))but the if-body runs regardless of what isIdField function returns.Here's the program:
Saving this into file
repro.zigand runningzig test src\repro.zig, I get the below unexpected error message:Expected Behavior
I'd expect this if-body to be never taken:
This is an extract from a bigger program, the contents of isIdField were originally more complicated until I noticed that it doesn't really matter what it returns.
I noticed #15122 and this bug kind of has a similar energy.
The text was updated successfully, but these errors were encountered: