zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 22432b15e31d506d070171b2932d5df71e9a1b9e (tree)
parent 215797749d0e0d911feaaf45dc70836c3d12f18e
Author: Vexu <git@vexu.eu>
Date:   Wed, 26 Feb 2020 11:07:47 +0200

add test for `@intToEnum`

Diffstat:
Mlib/std/fmt.zig | 6++----
Msrc-self-hosted/ir.zig | 2+-
Mtest/stage1/behavior/cast.zig | 11+++++++++++
3 files changed, 14 insertions(+), 5 deletions(-)

diff --git 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 @@ -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 @@ -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 {