From 8319844673c514bbf81d40fb7f38aba84067c69f Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Mon, 4 Mar 2024 08:02:48 +0100 Subject: [PATCH] feat: more checks --- lib/edlang_check/src/lib.rs | 1 - lib/edlang_lowering/src/lib.rs | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/edlang_check/src/lib.rs b/lib/edlang_check/src/lib.rs index 7cb80df31..3a21fffb4 100644 --- a/lib/edlang_check/src/lib.rs +++ b/lib/edlang_check/src/lib.rs @@ -85,7 +85,6 @@ pub fn lowering_error_to_report( .finish() }, LoweringError::UnexpectedType { span, found, expected } => { - dbg!(span); let mut labels = vec![ Label::new((path.clone(), span.into())) .with_message(format!("Unexpected type '{}', expected '{}'", found, expected.kind)) diff --git a/lib/edlang_lowering/src/lib.rs b/lib/edlang_lowering/src/lib.rs index cd9aad355..7ac375a6b 100644 --- a/lib/edlang_lowering/src/lib.rs +++ b/lib/edlang_lowering/src/lib.rs @@ -745,7 +745,7 @@ fn lower_binary_expr( ) -> Result<(ir::RValue, TypeKind, Span), LoweringError> { 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) .unwrap_or_else(|| find_expr_type(builder, rhs).expect("cant find type")); lower_expr( @@ -759,7 +759,7 @@ fn lower_binary_expr( } else { 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()); lower_expr( builder, @@ -773,6 +773,17 @@ fn lower_binary_expr( 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 { RValue::Use(op, _span) => op, lhs => {