Skip to content

Commit

Permalink
Add compile error when mapping single value to multiple fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Hejsil committed Oct 31, 2024
1 parent 08ce69d commit 5294e51
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mecha.zig
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ pub fn toStruct(comptime T: type) ToStructResult(T) {
@field(res, field.name) = value[i];
return res;
} else {
if (struct_fields.len != 1)
@compileError("Cannot map " ++ @typeName(@TypeOf(value)) ++ " to " ++ @typeName(T));
@field(res, struct_fields[0].name) = value;
return res;
}
Expand Down

0 comments on commit 5294e51

Please sign in to comment.