mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 05:48:31 +00:00
fix bitcast packed struct to integer and back
This commit is contained in:
parent
57347aacd7
commit
eaf74f4f96
@ -23254,9 +23254,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
|
||||
return result;
|
||||
}
|
||||
|
||||
IrInstruction *result = ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
|
||||
ir_assert(!(handle_is_ptr(dest_type) && !handle_is_ptr(src_type)), source_instr);
|
||||
return result;
|
||||
return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
|
||||
}
|
||||
|
||||
static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
|
||||
|
||||
@ -95,20 +95,20 @@ test "@bitCast extern structs at runtime and comptime" {
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
//test "bitcast packed struct to integer and back" {
|
||||
// const LevelUpMove = packed struct {
|
||||
// move_id: u9,
|
||||
// level: u7,
|
||||
// };
|
||||
// const S = struct {
|
||||
// fn doTheTest() void {
|
||||
// var move = LevelUpMove{ .move_id = 1, .level = 2 };
|
||||
// var v = @bitCast(u16, move);
|
||||
// var back_to_a_move = @bitCast(LevelUpMove, v);
|
||||
// expect(back_to_a_move.move_id == 1);
|
||||
// expect(back_to_a_move.level == 2);
|
||||
// }
|
||||
// };
|
||||
// S.doTheTest();
|
||||
// comptime S.doTheTest();
|
||||
//}
|
||||
test "bitcast packed struct to integer and back" {
|
||||
const LevelUpMove = packed struct {
|
||||
move_id: u9,
|
||||
level: u7,
|
||||
};
|
||||
const S = struct {
|
||||
fn doTheTest() void {
|
||||
var move = LevelUpMove{ .move_id = 1, .level = 2 };
|
||||
var v = @bitCast(u16, move);
|
||||
var back_to_a_move = @bitCast(LevelUpMove, v);
|
||||
expect(back_to_a_move.move_id == 1);
|
||||
expect(back_to_a_move.level == 2);
|
||||
}
|
||||
};
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user