mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
fix explicit casting from integer literal to float
This commit is contained in:
parent
5f0a9a569e
commit
15fe3c4235
@ -3783,7 +3783,19 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
|
||||
actual_type->id == TypeTableEntryIdNumLitInt)
|
||||
{
|
||||
if (num_lit_fits_in_other_type(g, expr_node, wanted_type)) {
|
||||
node->data.fn_call_expr.cast_op = CastOpNoop;
|
||||
if ((actual_type->id == TypeTableEntryIdNumLitFloat &&
|
||||
wanted_type->id == TypeTableEntryIdFloat) ||
|
||||
(actual_type->id == TypeTableEntryIdNumLitInt &&
|
||||
wanted_type->id == TypeTableEntryIdInt))
|
||||
{
|
||||
node->data.fn_call_expr.cast_op = CastOpNoop;
|
||||
} else if (wanted_type->id == TypeTableEntryIdInt) {
|
||||
node->data.fn_call_expr.cast_op = CastOpFloatToInt;
|
||||
} else if (wanted_type->id == TypeTableEntryIdFloat) {
|
||||
node->data.fn_call_expr.cast_op = CastOpIntToFloat;
|
||||
} else {
|
||||
zig_unreachable();
|
||||
}
|
||||
eval_const_expr_implicit_cast(g, node, expr_node);
|
||||
return wanted_type;
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user