| ... | @@ -1938,6 +1938,7 @@ fn zirEnumDecl( | ... | @@ -1938,6 +1938,7 @@ fn zirEnumDecl( |
| 1938 | var bit_bag_index: usize = body_end; | 1938 | var bit_bag_index: usize = body_end; |
| 1939 | var cur_bit_bag: u32 = undefined; | 1939 | var cur_bit_bag: u32 = undefined; |
| 1940 | var field_i: u32 = 0; | 1940 | var field_i: u32 = 0; |
| | 1941 | var last_tag_val: ?Value = null; |
| 1941 | while (field_i < fields_len) : (field_i += 1) { | 1942 | while (field_i < fields_len) : (field_i += 1) { |
| 1942 | if (field_i % 32 == 0) { | 1943 | if (field_i % 32 == 0) { |
| 1943 | cur_bit_bag = sema.code.extra[bit_bag_index]; | 1944 | cur_bit_bag = sema.code.extra[bit_bag_index]; |
| ... | @@ -1976,13 +1977,21 @@ fn zirEnumDecl( | ... | @@ -1976,13 +1977,21 @@ fn zirEnumDecl( |
| 1976 | // that points to this default value expression rather than the struct. | 1977 | // that points to this default value expression rather than the struct. |
| 1977 | // But only resolve the source location if we need to emit a compile error. | 1978 | // But only resolve the source location if we need to emit a compile error. |
| 1978 | const tag_val = (try sema.resolveInstConst(block, src, tag_val_ref)).val; | 1979 | const tag_val = (try sema.resolveInstConst(block, src, tag_val_ref)).val; |
| | 1980 | last_tag_val = tag_val; |
| 1979 | const copied_tag_val = try tag_val.copy(new_decl_arena_allocator); | 1981 | const copied_tag_val = try tag_val.copy(new_decl_arena_allocator); |
| 1980 | enum_obj.values.putAssumeCapacityNoClobberContext(copied_tag_val, {}, .{ | 1982 | enum_obj.values.putAssumeCapacityNoClobberContext(copied_tag_val, {}, .{ |
| 1981 | .ty = enum_obj.tag_ty, | 1983 | .ty = enum_obj.tag_ty, |
| 1982 | }); | 1984 | }); |
| 1983 | } else if (any_values) { | 1985 | } else if (any_values) { |
| 1984 | const tag_val = try Value.Tag.int_u64.create(new_decl_arena_allocator, field_i); | 1986 | const tag_val = if (last_tag_val) |val| |
| 1985 | enum_obj.values.putAssumeCapacityNoClobberContext(tag_val, {}, .{ .ty = enum_obj.tag_ty }); | 1987 | try val.intAdd(Value.one, sema.arena) |
| | 1988 | else |
| | 1989 | Value.zero; |
| | 1990 | last_tag_val = tag_val; |
| | 1991 | const copied_tag_val = try tag_val.copy(new_decl_arena_allocator); |
| | 1992 | enum_obj.values.putAssumeCapacityNoClobberContext(copied_tag_val, {}, .{ |
| | 1993 | .ty = enum_obj.tag_ty, |
| | 1994 | }); |
| 1986 | } | 1995 | } |
| 1987 | } | 1996 | } |
| 1988 | | 1997 | |