| author | |
| committer | |
| log | 3b4a6679a6422d68cb1ee4ecd31819b527b01c3b |
| tree | 6b85799065ac768d396648e4709378150394cb21 |
| parent | 695695c852b54c5cdc3f843e5ecd31b4349f2418 |
3 files changed, 20 insertions(+), 0 deletions(-)
src/ir.cpp+4| ... | @@ -15418,6 +15418,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15418,6 +15418,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15418 | bitcasted_value = nullptr; | 15418 | bitcasted_value = nullptr; |
| 15419 | } | 15419 | } |
| 15420 | 15420 | ||
| 15421 | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value.type)) { | ||
| 15422 | return bitcasted_value; | ||
| 15423 | } | ||
| 15424 | |||
| 15421 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, | 15425 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 15422 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); | 15426 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); |
| 15423 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || | 15427 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
test/compile_errors.zig+9| ... | @@ -1229,6 +1229,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1229,6 +1229,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1229 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", | 1229 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", |
| 1230 | ); | 1230 | ); |
| 1231 | 1231 | ||
| 1232 | cases.add( | ||
| 1233 | "@bitCast with different sizes inside an expression", | ||
| 1234 | \\export fn entry() void { | ||
| 1235 | \\ var foo = (@bitCast(u8, f32(1.0)) == 0xf); | ||
| 1236 | \\} | ||
| 1237 | , | ||
| 1238 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", | ||
| 1239 | ); | ||
| 1240 | |||
| 1232 | cases.add( | 1241 | cases.add( |
| 1233 | "attempted `&&`", | 1242 | "attempted `&&`", |
| 1234 | \\export fn entry(a: bool, b: bool) i32 { | 1243 | \\export fn entry(a: bool, b: bool) i32 { |
test/stage1/behavior/bitcast.zig+7| ... | @@ -139,3 +139,10 @@ test "bitcast packed struct literal to byte" { | ... | @@ -139,3 +139,10 @@ test "bitcast packed struct literal to byte" { |
| 139 | const casted = @bitCast(u8, Foo{ .value = 0xF }); | 139 | const casted = @bitCast(u8, Foo{ .value = 0xF }); |
| 140 | expect(casted == 0xf); | 140 | expect(casted == 0xf); |
| 141 | } | 141 | } |
| 142 | |||
| 143 | test "comptime bitcast used in expression has the correct type" { | ||
| 144 | const Foo = packed struct { | ||
| 145 | value: u8, | ||
| 146 | }; | ||
| 147 | expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf); | ||
| 148 | } |