authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-19 03:50:38-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-19 03:50:38-04:00
loga3ddd0826bd9c799768c0c707de72c21befa742a
tree685b621eb041c178af40c0044c74f689d8d6af7b
parent626b73e8beeaae1cab23f883f877d89d64bbfa39

remove enum to/from int casting syntax; add `@enumToInt`/`@intToEnum`

see #1061

9 files changed, 174 insertions(+), 51 deletions(-)

doc/langref.html.in+27-7
......@@ -1900,9 +1900,9 @@ const Value = enum(u2) {
19001900// Now you can cast between u2 and Value.
19011901// The ordinal value starts from 0, counting up for each member.
19021902test "enum ordinal value" {
1903 assert(u2(Value.Zero) == 0);
1904 assert(u2(Value.One) == 1);
1905 assert(u2(Value.Two) == 2);
1903 assert(@enumToInt(Value.Zero) == 0);
1904 assert(@enumToInt(Value.One) == 1);
1905 assert(@enumToInt(Value.Two) == 2);
19061906}
19071907
19081908// You can override the ordinal value for an enum.
......@@ -1912,9 +1912,9 @@ const Value2 = enum(u32) {
19121912 Million = 1000000,
19131913};
19141914test "set enum ordinal value" {
1915 assert(u32(Value2.Hundred) == 100);
1916 assert(u32(Value2.Thousand) == 1000);
1917 assert(u32(Value2.Million) == 1000000);
1915 assert(@enumToInt(Value2.Hundred) == 100);
1916 assert(@enumToInt(Value2.Thousand) == 1000);
1917 assert(@enumToInt(Value2.Million) == 1000000);
19181918}
19191919
19201920// Enums can have methods, the same as structs and unions.
......@@ -4931,6 +4931,14 @@ test "main" {
49314931 {#see_also|@import#}
49324932 {#header_close#}
49334933
4934 {#header_open|@enumToInt#}
4935 <pre><code class="zig">@enumToInt(enum_value: var) var</code></pre>
4936 <p>
4937 Converts an enumeration value into its integer tag type.
4938 </p>
4939 {#see_also|@intToEnum#}
4940 {#header_close#}
4941
49344942 {#header_open|@errSetCast#}
49354943 <pre><code class="zig">@errSetCast(comptime T: DestType, value: var) DestType</code></pre>
49364944 <p>
......@@ -5095,6 +5103,18 @@ fn add(a: i32, b: i32) i32 { return a + b; }
50955103 </p>
50965104 {#header_close#}
50975105
5106 {#header_open|@intToEnum#}
5107 <pre><code class="zig">@intToEnum(comptime DestType: type, int_value: @TagType(DestType)) DestType</code></pre>
5108 <p>
5109 Converts an integer into an {#link|enum#} value.
5110 </p>
5111 <p>
5112 Attempting to convert an integer which represents no value in the chosen enum type invokes
5113 safety-checked {#link|Undefined Behavior#}.
5114 </p>
5115 {#see_also|@enumToInt#}
5116 {#header_close#}
5117
50985118 {#header_open|@intToError#}
50995119 <pre><code class="zig">@intToError(value: @IntType(false, @sizeOf(error) * 8)) error</code></pre>
51005120 <p>
......@@ -6867,7 +6887,7 @@ hljs.registerLanguage("zig", function(t) {
68676887 a = t.IR + "\\s*\\(",
68686888 c = {
68696889 keyword: "const align var extern stdcallcc nakedcc volatile export pub noalias inline struct packed enum union break return try catch test continue unreachable comptime and or asm defer errdefer if else switch while for fn use bool f32 f64 void type noreturn error i8 u8 i16 u16 i32 u32 i64 u64 isize usize i8w u8w i16w i32w u32w i64w u64w isizew usizew c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong resume cancel await async orelse",
6870 built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic ptrCast intCast floatCast intToFloat floatToInt boolToInt bytesToSlice sliceToBytes errSetCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field typeInfo typeName newStackCall errorToInt intToError",
6890 built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic ptrCast intCast floatCast intToFloat floatToInt boolToInt bytesToSlice sliceToBytes errSetCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field typeInfo typeName newStackCall errorToInt intToError enumToInt intToEnum",
68716891 literal: "true false null undefined"
68726892 },
68736893 n = [e, t.CLCM, t.CBCM, s, r];
src/all_types.hpp+10
......@@ -1378,6 +1378,8 @@ enum BuiltinFnId {
13781378 BuiltinFnIdBoolToInt,
13791379 BuiltinFnIdErrToInt,
13801380 BuiltinFnIdIntToErr,
1381 BuiltinFnIdEnumToInt,
1382 BuiltinFnIdIntToEnum,
13811383 BuiltinFnIdIntType,
13821384 BuiltinFnIdSetCold,
13831385 BuiltinFnIdSetRuntimeSafety,
......@@ -2092,6 +2094,7 @@ enum IrInstructionId {
20922094 IrInstructionIdIntToPtr,
20932095 IrInstructionIdPtrToInt,
20942096 IrInstructionIdIntToEnum,
2097 IrInstructionIdEnumToInt,
20952098 IrInstructionIdIntToErr,
20962099 IrInstructionIdErrToInt,
20972100 IrInstructionIdCheckSwitchProngs,
......@@ -2905,6 +2908,13 @@ struct IrInstructionIntToPtr {
29052908struct IrInstructionIntToEnum {
29062909 IrInstruction base;
29072910
2911 IrInstruction *dest_type;
2912 IrInstruction *target;
2913};
2914
2915struct IrInstructionEnumToInt {
2916 IrInstruction base;
2917
29082918 IrInstruction *target;
29092919};
29102920
src/codegen.cpp+3
......@@ -4730,6 +4730,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
47304730 case IrInstructionIdErrSetCast:
47314731 case IrInstructionIdFromBytes:
47324732 case IrInstructionIdToBytes:
4733 case IrInstructionIdEnumToInt:
47334734 zig_unreachable();
47344735
47354736 case IrInstructionIdReturn:
......@@ -6325,6 +6326,8 @@ static void define_builtin_fns(CodeGen *g) {
63256326 create_builtin_fn(g, BuiltinFnIdBoolToInt, "boolToInt", 1);
63266327 create_builtin_fn(g, BuiltinFnIdErrToInt, "errorToInt", 1);
63276328 create_builtin_fn(g, BuiltinFnIdIntToErr, "intToError", 1);
6329 create_builtin_fn(g, BuiltinFnIdEnumToInt, "enumToInt", 1);
6330 create_builtin_fn(g, BuiltinFnIdIntToEnum, "intToEnum", 2);
63286331 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
63296332 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
63306333 create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
src/ir.cpp+105-13
......@@ -600,6 +600,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToEnum *) {
600600 return IrInstructionIdIntToEnum;
601601}
602602
603static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumToInt *) {
604 return IrInstructionIdEnumToInt;
605}
606
603607static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToErr *) {
604608 return IrInstructionIdIntToErr;
605609}
......@@ -2378,10 +2382,26 @@ static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode
23782382}
23792383
23802384static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode *source_node,
2381 IrInstruction *target)
2385 IrInstruction *dest_type, IrInstruction *target)
23822386{
23832387 IrInstructionIntToEnum *instruction = ir_build_instruction<IrInstructionIntToEnum>(
23842388 irb, scope, source_node);
2389 instruction->dest_type = dest_type;
2390 instruction->target = target;
2391
2392 if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block);
2393 ir_ref_instruction(target, irb->current_basic_block);
2394
2395 return &instruction->base;
2396}
2397
2398
2399
2400static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,
2401 IrInstruction *target)
2402{
2403 IrInstructionEnumToInt *instruction = ir_build_instruction<IrInstructionEnumToInt>(
2404 irb, scope, source_node);
23852405 instruction->target = target;
23862406
23872407 ir_ref_instruction(target, irb->current_basic_block);
......@@ -4708,6 +4728,31 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
47084728 // this value does not mean anything since we passed non-null values for other arg
47094729 AtomicOrderMonotonic);
47104730 }
4731 case BuiltinFnIdIntToEnum:
4732 {
4733 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4734 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
4735 if (arg0_value == irb->codegen->invalid_instruction)
4736 return arg0_value;
4737
4738 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4739 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
4740 if (arg1_value == irb->codegen->invalid_instruction)
4741 return arg1_value;
4742
4743 IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value);
4744 return ir_lval_wrap(irb, scope, result, lval);
4745 }
4746 case BuiltinFnIdEnumToInt:
4747 {
4748 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4749 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
4750 if (arg0_value == irb->codegen->invalid_instruction)
4751 return arg0_value;
4752
4753 IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value);
4754 return ir_lval_wrap(irb, scope, result, lval);
4755 }
47114756 }
47124757 zig_unreachable();
47134758}
......@@ -9951,7 +9996,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
99519996 }
99529997
99539998 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,
9954 source_instr->source_node, target);
9999 source_instr->source_node, nullptr, target);
995510000 result->value.type = wanted_type;
995610001 return result;
995710002}
......@@ -10485,16 +10530,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1048510530 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);
1048610531 }
1048710532
10488 // explicit cast from integer to enum type with no payload
10489 if (actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdEnum) {
10490 return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type);
10491 }
10492
10493 // explicit cast from enum type with no payload to integer
10494 if (wanted_type->id == TypeTableEntryIdInt && actual_type->id == TypeTableEntryIdEnum) {
10495 return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type);
10496 }
10497
1049810533 // explicit cast from union to the enum type of the union
1049910534 if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) {
1050010535 type_ensure_zero_bits_known(ira->codegen, actual_type);
......@@ -20262,11 +20297,63 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
2026220297 return result->value.type;
2026320298}
2026420299
20300static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
20301 IrInstruction *target = instruction->target->other;
20302 if (type_is_invalid(target->value.type))
20303 return ira->codegen->builtin_types.entry_invalid;
20304
20305 if (target->value.type->id != TypeTableEntryIdEnum) {
20306 ir_add_error(ira, instruction->target,
20307 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));
20308 return ira->codegen->builtin_types.entry_invalid;
20309 }
20310
20311 type_ensure_zero_bits_known(ira->codegen, target->value.type);
20312 if (type_is_invalid(target->value.type))
20313 return ira->codegen->builtin_types.entry_invalid;
20314
20315 TypeTableEntry *tag_type = target->value.type->data.enumeration.tag_int_type;
20316
20317 IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type);
20318 ir_link_new_instruction(result, &instruction->base);
20319 return result->value.type;
20320}
20321
20322static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
20323 IrInstruction *dest_type_value = instruction->dest_type->other;
20324 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
20325 if (type_is_invalid(dest_type))
20326 return ira->codegen->builtin_types.entry_invalid;
20327
20328 if (dest_type->id != TypeTableEntryIdEnum) {
20329 ir_add_error(ira, instruction->dest_type,
20330 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
20331 return ira->codegen->builtin_types.entry_invalid;
20332 }
20333
20334 type_ensure_zero_bits_known(ira->codegen, dest_type);
20335 if (type_is_invalid(dest_type))
20336 return ira->codegen->builtin_types.entry_invalid;
20337
20338 TypeTableEntry *tag_type = dest_type->data.enumeration.tag_int_type;
20339
20340 IrInstruction *target = instruction->target->other;
20341 if (type_is_invalid(target->value.type))
20342 return ira->codegen->builtin_types.entry_invalid;
20343
20344 IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type);
20345 if (type_is_invalid(casted_target->value.type))
20346 return ira->codegen->builtin_types.entry_invalid;
20347
20348 IrInstruction *result = ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type);
20349 ir_link_new_instruction(result, &instruction->base);
20350 return result->value.type;
20351}
20352
2026520353static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
2026620354 switch (instruction->id) {
2026720355 case IrInstructionIdInvalid:
2026820356 case IrInstructionIdWidenOrShorten:
20269 case IrInstructionIdIntToEnum:
2027020357 case IrInstructionIdStructInit:
2027120358 case IrInstructionIdUnionInit:
2027220359 case IrInstructionIdStructFieldPtr:
......@@ -20531,6 +20618,10 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
2053120618 return ir_analyze_instruction_int_to_err(ira, (IrInstructionIntToErr *)instruction);
2053220619 case IrInstructionIdErrToInt:
2053320620 return ir_analyze_instruction_err_to_int(ira, (IrInstructionErrToInt *)instruction);
20621 case IrInstructionIdIntToEnum:
20622 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);
20623 case IrInstructionIdEnumToInt:
20624 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);
2053420625 }
2053520626 zig_unreachable();
2053620627}
......@@ -20754,6 +20845,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2075420845 case IrInstructionIdBoolToInt:
2075520846 case IrInstructionIdFromBytes:
2075620847 case IrInstructionIdToBytes:
20848 case IrInstructionIdEnumToInt:
2075720849 return false;
2075820850
2075920851 case IrInstructionIdAsm:
src/ir_print.cpp+14
......@@ -928,6 +928,17 @@ static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction
928928
929929static void ir_print_int_to_enum(IrPrint *irp, IrInstructionIntToEnum *instruction) {
930930 fprintf(irp->f, "@intToEnum(");
931 if (instruction->dest_type == nullptr) {
932 fprintf(irp->f, "(null)");
933 } else {
934 ir_print_other_instruction(irp, instruction->dest_type);
935 }
936 ir_print_other_instruction(irp, instruction->target);
937 fprintf(irp->f, ")");
938}
939
940static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instruction) {
941 fprintf(irp->f, "@enumToInt(");
931942 ir_print_other_instruction(irp, instruction->target);
932943 fprintf(irp->f, ")");
933944}
......@@ -1717,6 +1728,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
17171728 case IrInstructionIdAtomicLoad:
17181729 ir_print_atomic_load(irp, (IrInstructionAtomicLoad *)instruction);
17191730 break;
1731 case IrInstructionIdEnumToInt:
1732 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
1733 break;
17201734 }
17211735 fprintf(irp->f, "\n");
17221736}
std/json.zig+1-1
......@@ -180,7 +180,7 @@ pub const StreamingParser = struct {
180180 pub fn fromInt(x: var) State {
181181 debug.assert(x == 0 or x == 1);
182182 const T = @TagType(State);
183 return State(@intCast(T, x));
183 return @intToEnum(State, @intCast(T, x));
184184 }
185185 };
186186
test/cases/enum.zig+8-8
......@@ -92,14 +92,14 @@ test "enum to int" {
9292}
9393
9494fn shouldEqual(n: Number, expected: u3) void {
95 assert(u3(n) == expected);
95 assert(@enumToInt(n) == expected);
9696}
9797
9898test "int to enum" {
9999 testIntToEnumEval(3);
100100}
101101fn testIntToEnumEval(x: i32) void {
102 assert(IntToEnumNumber(@intCast(u3, x)) == IntToEnumNumber.Three);
102 assert(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
103103}
104104const IntToEnumNumber = enum {
105105 Zero,
......@@ -768,7 +768,7 @@ test "casting enum to its tag type" {
768768}
769769
770770fn testCastEnumToTagType(value: Small2) void {
771 assert(u2(value) == 1);
771 assert(@enumToInt(value) == 1);
772772}
773773
774774const MultipleChoice = enum(u32) {
......@@ -784,7 +784,7 @@ test "enum with specified tag values" {
784784}
785785
786786fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
787 assert(u32(x) == 60);
787 assert(@enumToInt(x) == 60);
788788 assert(1234 == switch (x) {
789789 MultipleChoice.A => 1,
790790 MultipleChoice.B => 2,
......@@ -811,7 +811,7 @@ test "enum with specified and unspecified tag values" {
811811}
812812
813813fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
814 assert(u32(x) == 1000);
814 assert(@enumToInt(x) == 1000);
815815 assert(1234 == switch (x) {
816816 MultipleChoice2.A => 1,
817817 MultipleChoice2.B => 2,
......@@ -826,8 +826,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
826826}
827827
828828test "cast integer literal to enum" {
829 assert(MultipleChoice2(0) == MultipleChoice2.Unspecified1);
830 assert(MultipleChoice2(40) == MultipleChoice2.B);
829 assert(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
830 assert(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
831831}
832832
833833const EnumWithOneMember = enum {
......@@ -865,7 +865,7 @@ const EnumWithTagValues = enum(u4) {
865865 D = 1 << 3,
866866};
867867test "enum with tag values don't require parens" {
868 assert(u4(EnumWithTagValues.C) == 0b0100);
868 assert(@enumToInt(EnumWithTagValues.C) == 0b0100);
869869}
870870
871871test "enum with 1 field but explicit tag type should still have the tag type" {
test/cases/union.zig+2-2
......@@ -126,7 +126,7 @@ const MultipleChoice = union(enum(u32)) {
126126test "simple union(enum(u32))" {
127127 var x = MultipleChoice.C;
128128 assert(x == MultipleChoice.C);
129 assert(u32(@TagType(MultipleChoice)(x)) == 60);
129 assert(@enumToInt(@TagType(MultipleChoice)(x)) == 60);
130130}
131131
132132const MultipleChoice2 = union(enum(u32)) {
......@@ -148,7 +148,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
148148}
149149
150150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: *const MultipleChoice2) void {
151 assert(u32(@TagType(MultipleChoice2)(x.*)) == 60);
151 assert(@enumToInt(@TagType(MultipleChoice2)(x.*)) == 60);
152152 assert(1123 == switch (x.*) {
153153 MultipleChoice2.A => 1,
154154 MultipleChoice2.B => 2,
test/compile_errors.zig+4-20
......@@ -3709,22 +3709,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37093709 ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'",
37103710 );
37113711
3712 cases.add(
3713 "explicitly casting enum to non tag type",
3714 \\const Small = enum(u2) {
3715 \\ One,
3716 \\ Two,
3717 \\ Three,
3718 \\ Four,
3719 \\};
3720 \\
3721 \\export fn entry() void {
3722 \\ var x = u3(Small.Two);
3723 \\}
3724 ,
3725 ".tmp_source.zig:9:15: error: enum to integer cast to 'u3' instead of its tag type, 'u2'",
3726 );
3727
37283712 cases.add(
37293713 "explicitly casting non tag type to enum",
37303714 \\const Small = enum(u2) {
......@@ -3736,10 +3720,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37363720 \\
37373721 \\export fn entry() void {
37383722 \\ var y = u3(3);
3739 \\ var x = Small(y);
3723 \\ var x = @intToEnum(Small, y);
37403724 \\}
37413725 ,
3742 ".tmp_source.zig:10:18: error: integer to enum cast from 'u3' instead of its tag type, 'u2'",
3726 ".tmp_source.zig:10:31: error: expected type 'u2', found 'u3'",
37433727 );
37443728
37453729 cases.add(
......@@ -4020,10 +4004,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
40204004 \\ B = 11,
40214005 \\};
40224006 \\export fn entry() void {
4023 \\ var x = Foo(0);
4007 \\ var x = @intToEnum(Foo, 0);
40244008 \\}
40254009 ,
4026 ".tmp_source.zig:6:16: error: enum 'Foo' has no tag matching integer value 0",
4010 ".tmp_source.zig:6:13: error: enum 'Foo' has no tag matching integer value 0",
40274011 ".tmp_source.zig:1:13: note: 'Foo' declared here",
40284012 );
40294013