From c657084451b4344e941cf6acd606b2c7a46321d4 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 9 Nov 2024 14:02:13 +0100 Subject: [PATCH] integer constants can be casted to floats if type is known to be a float --- lang/src/son.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lang/src/son.rs b/lang/src/son.rs index e816810..1e67402 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -2486,6 +2486,12 @@ impl<'a> Codegen<'a> { } } Expr::Bool { value, .. } => Some(self.ci.nodes.new_const_lit(ty::Id::BOOL, value)), + Expr::Number { value, .. } + if let Some(ty) = ctx.ty + && ty.is_float() => + { + Some(self.ci.nodes.new_const_lit(ty, (value as f64).to_bits() as i64)) + } Expr::Number { value, .. } => Some( self.ci.nodes.new_const_lit( ctx.ty