implementation for bitcasting extern enum type to c_int

closes #1036
This commit is contained in:
Andrew Kelley 2018-09-18 15:00:14 -04:00
parent 5fd3af9dc6
commit 8c77c5705f
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 22 additions and 2 deletions

View File

@ -20254,6 +20254,11 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
codegen->is_big_endian);
return;
case ZigTypeIdEnum:
bigint_write_twos_complement(&val->data.x_enum_tag, buf,
val->type->data.enumeration.tag_int_type->data.integral.bit_count,
codegen->is_big_endian);
return;
case ZigTypeIdFloat:
float_write_ieee597(val, buf, codegen->is_big_endian);
return;
@ -20285,8 +20290,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
zig_panic("TODO buf_write_value_bytes error union");
case ZigTypeIdErrorSet:
zig_panic("TODO buf_write_value_bytes pure error type");
case ZigTypeIdEnum:
zig_panic("TODO buf_write_value_bytes enum type");
case ZigTypeIdFn:
zig_panic("TODO buf_write_value_bytes fn type");
case ZigTypeIdUnion:

View File

@ -16,3 +16,20 @@ fn conv(x: i32) u32 {
fn conv2(x: u32) i32 {
return @bitCast(i32, x);
}
test "@bitCast extern enum to its integer type" {
const SOCK = extern enum {
A,
B,
fn testBitCastExternEnum() void {
var SOCK_DGRAM = @This().B;
var sock_dgram = @bitCast(c_int, SOCK_DGRAM);
assert(sock_dgram == 1);
}
};
SOCK.testBitCastExternEnum();
comptime SOCK.testBitCastExternEnum();
}