| author | |
| committer | |
| log | 768d1fc539e425280acba5b30256e3b1267ddfbb |
| tree | 84ce94293869ea0d9706d9125f7ca38190ec3e97 |
| parent | ffb3b1576b1c02942bce89ef05eaf05fe2f026ac |
2 files changed, 15 insertions(+), 0 deletions(-)
src/ir.cpp+6| ... | ... | @@ -18497,6 +18497,12 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns |
| 18497 | 18497 | if (type_is_invalid(target->value.type)) |
| 18498 | 18498 | return ira->codegen->builtin_types.entry_invalid; |
| 18499 | 18499 | |
| 18500 | if (target->value.type->id != TypeTableEntryIdFloat && target->value.type->id != TypeTableEntryIdComptimeFloat) { | |
| 18501 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", | |
| 18502 | buf_ptr(&target->value.type->name))); | |
| 18503 | return ira->codegen->builtin_types.entry_invalid; | |
| 18504 | } | |
| 18505 | ||
| 18500 | 18506 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false); |
| 18501 | 18507 | ir_link_new_instruction(result, &instruction->base); |
| 18502 | 18508 | return dest_type; |
test/compile_errors.zig+9| ... | ... | @@ -495,6 +495,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 495 | 495 | ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'", |
| 496 | 496 | ); |
| 497 | 497 | |
| 498 | cases.add( | |
| 499 | "non float passed to @floatToInt", | |
| 500 | \\export fn entry() void { | |
| 501 | \\ const x = @floatToInt(i32, 54); | |
| 502 | \\} | |
| 503 | , | |
| 504 | ".tmp_source.zig:2:32: error: expected float type, found 'comptime_int'", | |
| 505 | ); | |
| 506 | ||
| 498 | 507 | cases.add( |
| 499 | 508 | "use implicit casts to assign null to non-nullable pointer", |
| 500 | 509 | \\export fn entry() void { |