stage1: @intToEnum implicitly does an @intCast

This is a backwards-compatible language change.

Previously, `@intToEnum` coerced its integer operand to the integer tag
type of the destination enum type, often requiring the callsite to
additionally wrap the operand in an `@intCast`. Now, the `@intCast` is
implicit, and any integer operand can be passed to `@intToEnum`.

The same as before, it is illegal behavior to pass any integer which does
not have a corresponding enum tag.
This commit is contained in:
Andrew Kelley
2021-08-23 15:30:57 -07:00
parent d5ef5da594
commit bb38931c71
4 changed files with 32 additions and 19 deletions
+2 -2
View File
@@ -7691,12 +7691,12 @@ pub fn addCases(ctx: *TestContext) !void {
\\};
\\
\\export fn entry() void {
\\ var y = @as(u3, 3);
\\ var y = @as(f32, 3);
\\ var x = @intToEnum(Small, y);
\\ _ = x;
\\}
, &[_][]const u8{
"tmp.zig:10:31: error: expected type 'u2', found 'u3'",
"tmp.zig:10:31: error: expected integer type, found 'f32'",
});
ctx.objErrStage1("union fields with value assignments",