This commit is contained in:
Edgar 2023-05-27 17:22:07 +02:00
parent bab8eec51f
commit 84e6cc630e
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
2 changed files with 13 additions and 6 deletions

View file

@ -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);
}

View file

@ -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");