From 84e6cc630eb2da0d847b2478e9fcfed43de70b6e Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Sat, 27 May 2023 17:22:07 +0200 Subject: [PATCH] fixes --- simple.ed | 14 ++++++++++---- src/codegen.rs | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/simple.ed b/simple.ed index d0bb99f6c..9771374de 100644 --- a/simple.ed +++ b/simple.ed @@ -7,12 +7,18 @@ fn test(x: Hello) { return; } -fn works(x: i32) -> i32 { - return x * 4; +fn works(x: i64) -> i64 { + let z: i64 = 0; + if x == 2 { + z = x * 2; + } else { + z = x * 3; + } + return z; } -fn main() -> i32 { - let y = 2; +fn main() -> i64 { + let y: i64 = 2; let z = y; return works(z); } diff --git a/src/codegen.rs b/src/codegen.rs index d0b3a175d..bb23e98b9 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -295,7 +295,7 @@ impl<'ctx> CodeGen<'ctx> { self.functions.get(function).unwrap().clone().1 } Expression::BinaryOp(lhs, op, rhs) => match op { - OpCode::Eq | OpCode::Ne => Some(TypeExp::Boolean), + //OpCode::Eq | OpCode::Ne => Some(TypeExp::Boolean), _ => self .find_expr_type(lhs, variables) .or_else(|| self.find_expr_type(rhs, variables)), @@ -386,8 +386,9 @@ impl<'ctx> CodeGen<'ctx> { body, else_body, } => { + let type_hint = self.find_expr_type(condition, variables); let (condition, _cond_type) = self - .compile_expression(condition, variables, types, Some(TypeExp::Boolean))? + .compile_expression(condition, variables, types, type_hint)? .expect("should produce a value"); let mut if_block = self.context.append_basic_block(function_value, "if");