mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
Added compilation error when a non-float is given to @floatToInt()
This commit is contained in:
parent
ffb3b1576b
commit
768d1fc539
@ -18497,6 +18497,12 @@ 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 != 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)));
|
||||
return ira->codegen->builtin_types.entry_invalid;
|
||||
}
|
||||
|
||||
IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
|
||||
ir_link_new_instruction(result, &instruction->base);
|
||||
return dest_type;
|
||||
|
||||
@ -495,6 +495,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"non float passed to @floatToInt",
|
||||
\\export fn entry() void {
|
||||
\\ const x = @floatToInt(i32, 54);
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:2:32: error: expected float type, found 'comptime_int'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"use implicit casts to assign null to non-nullable pointer",
|
||||
\\export fn entry() void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user