Naive typechecking of binary operators
This commit is contained in:
parent
4f7fa0f5e3
commit
7218898ce0
@ -31,7 +31,25 @@ impl Typed for Expression<'_> {
|
|||||||
}
|
}
|
||||||
Expression::FunctionCall(_) => todo!(),
|
Expression::FunctionCall(_) => todo!(),
|
||||||
Expression::UnaryOperator(_, _) => todo!(),
|
Expression::UnaryOperator(_, _) => todo!(),
|
||||||
Expression::BinaryOperator(_, _, _) => todo!(),
|
Expression::BinaryOperator(exp1, exp2, operator) => {
|
||||||
|
let t1 = exp1.get_type(scope)?;
|
||||||
|
let t2 = exp2.get_type(scope)?;
|
||||||
|
|
||||||
|
// TODO: There's definitely a better way to do this
|
||||||
|
if *operator == "+" && t1 == "Int" && t2 == "Int" {
|
||||||
|
return Ok("Int".into());
|
||||||
|
} else if *operator == "-" && t1 == "Int" && t2 == "Int" {
|
||||||
|
return Ok("Int".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Err(MistiError::Semantic(SemanticError {
|
||||||
|
error_start: 0,
|
||||||
|
error_end: 1,
|
||||||
|
reason: format!(
|
||||||
|
"Unsupported binary operator or invalid arguments to the operator."
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user