authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-02-26 11:07:47+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-26 11:19:40-05:00
log22432b15e31d506d070171b2932d5df71e9a1b9e
tree9562bb32559ea9554c3866e4a26e2475b71058df
parent215797749d0e0d911feaaf45dc70836c3d12f18e
signature Commit is signed but in an unrecognized format.

add test for `@intToEnum`


3 files changed, 14 insertions(+), 5 deletions(-)

lib/std/fmt.zig+2-4
......@@ -414,10 +414,9 @@ pub fn formatType(
414414 if (max_depth == 0) {
415415 return output(context, "{ ... }");
416416 }
417 comptime var field_i = 0;
418417 try output(context, "{");
419 inline for (StructT.fields) |f| {
420 if (field_i == 0) {
418 inline for (StructT.fields) |f, i| {
419 if (i == 0) {
421420 try output(context, " .");
422421 } else {
423422 try output(context, ", .");
......@@ -425,7 +424,6 @@ pub fn formatType(
425424 try output(context, f.name);
426425 try output(context, " = ");
427426 try formatType(@field(value, f.name), fmt, options, context, Errors, output, max_depth - 1);
428 field_i += 1;
429427 }
430428 try output(context, " }");
431429 },
src-self-hosted/ir.zig+1-1
......@@ -1803,7 +1803,7 @@ pub const Builder = struct {
18031803
18041804 // Look at the params and ref() other instructions
18051805 inline for (@typeInfo(I.Params).Struct.fields) |f| {
1806 switch (f.fiedl_type) {
1806 switch (f.field_type) {
18071807 *Inst => @field(inst.params, f.name).ref(self),
18081808 *BasicBlock => @field(inst.params, f.name).ref(self),
18091809 ?*Inst => if (@field(inst.params, f.name)) |other| other.ref(self),
test/stage1/behavior/cast.zig+11
......@@ -491,6 +491,17 @@ test "@intToEnum passed a comptime_int to an enum with one item" {
491491 expect(x == E.A);
492492}
493493
494test "@intToEnum runtime to an extern enum with duplicate values" {
495 const E = extern enum(u8) {
496 A = 1,
497 B = 1,
498 };
499 var a: u8 = 1;
500 var x = @intToEnum(E, a);
501 expect(x == E.A);
502 expect(x == E.B);
503}
504
494505test "@intCast to u0 and use the result" {
495506 const S = struct {
496507 fn doTheTest(zero: u1, one: u1, bigzero: i32) void {