| ... | ... | @@ -275,7 +275,9 @@ pub fn zeroes(comptime T: type) T { |
| 275 | 275 | } else { |
| 276 | 276 | var structure: T = undefined; |
| 277 | 277 | inline for (struct_info.fields) |field| { |
| 278 | | @field(structure, field.name) = zeroes(@TypeOf(@field(structure, field.name))); |
| 278 | if (!field.is_comptime) { |
| 279 | @field(structure, field.name) = zeroes(@TypeOf(@field(structure, field.name))); |
| 280 | } |
| 279 | 281 | } |
| 280 | 282 | return structure; |
| 281 | 283 | } |
| ... | ... | @@ -342,6 +344,8 @@ test "mem.zeroes" { |
| 342 | 344 | try testing.expect(a.y == 10); |
| 343 | 345 | |
| 344 | 346 | const ZigStruct = struct { |
| 347 | comptime comptime_field: u8 = 5, |
| 348 | |
| 345 | 349 | integral_types: struct { |
| 346 | 350 | integer_0: i0, |
| 347 | 351 | integer_8: i8, |
| ... | ... | @@ -376,6 +380,7 @@ test "mem.zeroes" { |
| 376 | 380 | }; |
| 377 | 381 | |
| 378 | 382 | const b = zeroes(ZigStruct); |
| 383 | try testing.expectEqual(@as(u8, 5), b.comptime_field); |
| 379 | 384 | try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0); |
| 380 | 385 | try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8); |
| 381 | 386 | try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16); |