From f7d5bccdd91cd6ab2c7cfa9141eb91c3d03db5c2 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Mon, 16 Dec 2024 13:49:20 +0100 Subject: [PATCH] fixing @itf type inference Signed-off-by: Jakub Doka --- lang/src/son.rs | 11 ++++------- lang/src/ty.rs | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lang/src/son.rs b/lang/src/son.rs index 09b4c67..71693b2 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -3648,18 +3648,15 @@ impl<'a> Codegen<'a> { self.tys, )) } - Expr::Directive { name: "itf", args: [expr], .. } => { + Expr::Directive { name: "itf", args: [expr], pos } => { let mut val = self.expr_ctx(expr, Ctx::default().with_ty(ty::Id::INT))?; - let (ret_ty, expected) = match val.ty.simple_size().unwrap() { - 8 => (ty::Id::F64, ty::Id::INT), - _ => (ty::Id::F32, ty::Id::INT), - }; + inference!(fty, ctx, self, pos, "float", "@as())"); - self.assert_ty(expr.pos(), &mut val, expected, "converted integer"); + self.assert_ty(expr.pos(), &mut val, ty::Id::INT, "converted integer"); Some(self.ci.nodes.new_node_lit( - ret_ty, + fty, Kind::UnOp { op: TokenKind::Float }, [VOID, val.id], self.tys, diff --git a/lang/src/ty.rs b/lang/src/ty.rs index 6dfb1ad..107d4ab 100644 --- a/lang/src/ty.rs +++ b/lang/src/ty.rs @@ -223,6 +223,7 @@ impl Id { _ if oa == ob => oa, _ if ob.is_optional() => ob, _ if oa.is_pointer() && ob.is_pointer() => return None, + _ if oa == Id::BOOL && ob.is_integer() => ob, _ if a.is_signed() && b.is_signed() || a.is_unsigned() && b.is_unsigned() => ob, _ if a.is_unsigned() && b.is_signed() && a.repr() - U8 < b.repr() - I8 => ob, _ if a.is_unsigned() && b.is_signed() && a.repr() - U8 > b.repr() - I8 => oa,