authorgravatar for 42674143+hcff@users.noreply.github.comhfcc <42674143+hcff@users.noreply.github.com> 2018-09-05 23:31:25+02:00
committergravatar for 42674143+hcff@users.noreply.github.comhfcc <42674143+hcff@users.noreply.github.com> 2018-09-05 23:31:25+02:00
log768d1fc539e425280acba5b30256e3b1267ddfbb
tree84ce94293869ea0d9706d9125f7ca38190ec3e97
parentffb3b1576b1c02942bce89ef05eaf05fe2f026ac

Added compilation error when a non-float is given to @floatToInt()


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
1849718497 if (type_is_invalid(target->value.type))
1849818498 return ira->codegen->builtin_types.entry_invalid;
1849918499
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
1850018506 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
1850118507 ir_link_new_instruction(result, &instruction->base);
1850218508 return dest_type;
test/compile_errors.zig+9
......@@ -495,6 +495,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
495495 ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
496496 );
497497
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
498507 cases.add(
499508 "use implicit casts to assign null to non-nullable pointer",
500509 \\export fn entry() void {