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