From b517bea734c0141fcda6b267a8f0de34cddc65f8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Sep 2018 18:01:48 -0400 Subject: allow comptime_int to @floatToInt --- src/ir.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index e928dc4f7b..8c44363bbe 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -18497,6 +18497,14 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; + if (target->value.type->id == TypeTableEntryIdComptimeInt) { + IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type); + if (type_is_invalid(casted_value->value.type)) + return ira->codegen->builtin_types.entry_invalid; + ir_link_new_instruction(casted_value, &instruction->base); + return casted_value->value.type; + } + if (target->value.type->id != TypeTableEntryIdFloat && target->value.type->id != TypeTableEntryIdComptimeFloat) { ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", buf_ptr(&target->value.type->name))); -- cgit v1.2.3