feat: more checks

This commit is contained in:
Edgar 2024-03-04 08:02:48 +01:00
parent f71abb0b26
commit 8319844673
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
2 changed files with 13 additions and 3 deletions

View file

@ -85,7 +85,6 @@ pub fn lowering_error_to_report(
.finish() .finish()
}, },
LoweringError::UnexpectedType { span, found, expected } => { LoweringError::UnexpectedType { span, found, expected } => {
dbg!(span);
let mut labels = vec![ let mut labels = vec![
Label::new((path.clone(), span.into())) Label::new((path.clone(), span.into()))
.with_message(format!("Unexpected type '{}', expected '{}'", found, expected.kind)) .with_message(format!("Unexpected type '{}', expected '{}'", found, expected.kind))

View file

@ -745,7 +745,7 @@ fn lower_binary_expr(
) -> Result<(ir::RValue, TypeKind, Span), LoweringError> { ) -> Result<(ir::RValue, TypeKind, Span), LoweringError> {
trace!("lowering binary op: {:?}", op); trace!("lowering binary op: {:?}", op);
let (lhs, lhs_ty, _) = if type_hint.is_none() { let (lhs, lhs_ty, lhs_span) = if type_hint.is_none() {
let ty = find_expr_type(builder, lhs) let ty = find_expr_type(builder, lhs)
.unwrap_or_else(|| find_expr_type(builder, rhs).expect("cant find type")); .unwrap_or_else(|| find_expr_type(builder, rhs).expect("cant find type"));
lower_expr( lower_expr(
@ -759,7 +759,7 @@ fn lower_binary_expr(
} else { } else {
lower_expr(builder, lhs, type_hint)? lower_expr(builder, lhs, type_hint)?
}; };
let (rhs, rhs_ty, _) = if type_hint.is_none() { let (rhs, rhs_ty, rhs_span) = if type_hint.is_none() {
let ty = find_expr_type(builder, rhs).unwrap_or(lhs_ty.clone()); let ty = find_expr_type(builder, rhs).unwrap_or(lhs_ty.clone());
lower_expr( lower_expr(
builder, builder,
@ -773,6 +773,17 @@ fn lower_binary_expr(
lower_expr(builder, rhs, type_hint)? lower_expr(builder, rhs, type_hint)?
}; };
if lhs_ty != rhs_ty {
return Err(LoweringError::UnexpectedType {
span: rhs_span,
found: rhs_ty,
expected: TypeInfo {
span: Some(lhs_span),
kind: lhs_ty,
},
});
}
let lhs = match lhs { let lhs = match lhs {
RValue::Use(op, _span) => op, RValue::Use(op, _span) => op,
lhs => { lhs => {