fixing @itf type inference

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-16 13:49:20 +01:00
parent 07d4fe416a
commit f7d5bccdd9
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 5 additions and 7 deletions

View file

@ -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(<float-ty, @itf(<expr>))");
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,

View file

@ -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,