add test for @intToEnum

This commit is contained in:
Vexu 2020-02-26 11:07:47 +02:00 committed by Andrew Kelley
parent 215797749d
commit 22432b15e3
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 14 additions and 5 deletions

View File

@ -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, " }");
},

View File

@ -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),

View File

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