mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
Fix comptime bitcast inside an expression
This commit is contained in:
parent
695695c852
commit
3b4a6679a6
@ -15418,6 +15418,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
|
||||
bitcasted_value = nullptr;
|
||||
}
|
||||
|
||||
if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value.type)) {
|
||||
return bitcasted_value;
|
||||
}
|
||||
|
||||
IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
|
||||
dest_type, bitcasted_value, force_runtime, non_null_comptime, true);
|
||||
if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
|
||||
|
||||
@ -1229,6 +1229,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
"tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"@bitCast with different sizes inside an expression",
|
||||
\\export fn entry() void {
|
||||
\\ var foo = (@bitCast(u8, f32(1.0)) == 0xf);
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"attempted `&&`",
|
||||
\\export fn entry(a: bool, b: bool) i32 {
|
||||
|
||||
@ -139,3 +139,10 @@ test "bitcast packed struct literal to byte" {
|
||||
const casted = @bitCast(u8, Foo{ .value = 0xF });
|
||||
expect(casted == 0xf);
|
||||
}
|
||||
|
||||
test "comptime bitcast used in expression has the correct type" {
|
||||
const Foo = packed struct {
|
||||
value: u8,
|
||||
};
|
||||
expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user