Skip to content

Commit 2994a20

Browse files
committed
Merge branch 'master' into kt128r
* master: std.Zig.AstGen: handle properly .inferred_ptr and .destructure in enum_literal handling std.testing: Fix expectEqualDeep formatted enum (ziglang#25960)
2 parents 13f1fa7 + d0ba664 commit 2994a20

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/std/testing.zig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
760760
.error_set,
761761
=> {
762762
if (actual != expected) {
763-
print("expected {}, found {}\n", .{ expected, actual });
763+
print("expected {any}, found {any}\n", .{ expected, actual });
764764
return error.TestExpectedEqual;
765765
}
766766
},
@@ -923,6 +923,18 @@ test "expectEqualDeep primitive type" {
923923
}.foo;
924924
try expectEqualDeep(fnType, fnType);
925925
}
926+
// enum with formatter
927+
{
928+
const TestEnum = enum {
929+
a,
930+
b,
931+
932+
pub fn format(self: @This(), writer: *std.Io.Writer) !void {
933+
try writer.writeAll(@tagName(self));
934+
}
935+
};
936+
try expectEqualDeep(TestEnum.b, TestEnum.b);
937+
}
926938
}
927939

928940
test "expectEqualDeep pointer" {

lib/std/zig/AstGen.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,9 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
10061006
.field_name_start = str_index,
10071007
});
10081008
switch (ri.rl) {
1009-
.discard, .none, .ref => unreachable, // no result type
1009+
.discard, .none, .ref, .inferred_ptr, .destructure => unreachable, // no result type
10101010
.ty, .coerced_ty => return res, // `decl_literal` does the coercion for us
1011-
.ref_coerced_ty, .ptr, .inferred_ptr, .destructure => return rvalue(gz, ri, res, node),
1011+
.ref_coerced_ty, .ptr => return rvalue(gz, ri, res, node),
10121012
}
10131013
} else return simpleStrTok(gz, ri, tree.nodeMainToken(node), node, .enum_literal),
10141014
.error_value => return simpleStrTok(gz, ri, tree.nodeMainToken(node) + 2, node, .error_value),

0 commit comments

Comments
 (0)