From 22432b15e31d506d070171b2932d5df71e9a1b9e Mon Sep 17 00:00:00 2001 From: Vexu Date: Wed, 26 Feb 2020 11:07:47 +0200 Subject: [PATCH] add test for `@intToEnum` --- lib/std/fmt.zig | 6 ++---- src-self-hosted/ir.zig | 2 +- test/stage1/behavior/cast.zig | 11 +++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index b9c6dd00334042d70d0f68ebed91a2539bcbf9cd..d0931016461ecd0d770182330f37582792ffde27 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -414,10 +414,9 @@ pub fn formatType( if (max_depth == 0) { return output(context, "{ ... }"); } - comptime var field_i = 0; try output(context, "{"); - inline for (StructT.fields) |f| { - if (field_i == 0) { + inline for (StructT.fields) |f, i| { + if (i == 0) { try output(context, " ."); } else { try output(context, ", ."); @@ -425,7 +424,6 @@ pub fn formatType( try output(context, f.name); try output(context, " = "); try formatType(@field(value, f.name), fmt, options, context, Errors, output, max_depth - 1); - field_i += 1; } try output(context, " }"); }, diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig index 576294a7d7cde8f97ba23b3f8fc48f06b97e8347..2e65962d415a5857df0d80c87257746a525e8268 100644 --- a/src-self-hosted/ir.zig +++ b/src-self-hosted/ir.zig @@ -1803,7 +1803,7 @@ pub const Builder = struct { // Look at the params and ref() other instructions inline for (@typeInfo(I.Params).Struct.fields) |f| { - switch (f.fiedl_type) { + switch (f.field_type) { *Inst => @field(inst.params, f.name).ref(self), *BasicBlock => @field(inst.params, f.name).ref(self), ?*Inst => if (@field(inst.params, f.name)) |other| other.ref(self), diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index 76d3b784ec96b2b61ec4d805bc4c235467a042a5..d2267a3753519e9c1b7da843c0e168205b7e468c 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -491,6 +491,17 @@ test "@intToEnum passed a comptime_int to an enum with one item" { expect(x == E.A); } +test "@intToEnum runtime to an extern enum with duplicate values" { + const E = extern enum(u8) { + A = 1, + B = 1, + }; + var a: u8 = 1; + var x = @intToEnum(E, a); + expect(x == E.A); + expect(x == E.B); +} + test "@intCast to u0 and use the result" { const S = struct { fn doTheTest(zero: u1, one: u1, bigzero: i32) void { -- 2.54.0