From c15ca6ca53c7d144c3add0cff937c5c96f804926 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:41:20 -0700 Subject: [PATCH] create error for tuple length mismatch --- compiler/passes/src/type_checking/check_statements.rs | 9 ++++++++- errors/src/errors/type_checker/type_checker_error.rs | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index 436de46bfe..40aa65e79d 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -210,7 +210,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { } }; - // Insert the variables in the into the symbol table. + // Insert the variables into the symbol table. match &input.place { Expression::Identifier(identifier) => { insert_variable(identifier.name, input.type_.clone(), identifier.span, declaration) @@ -222,6 +222,13 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { "Type checking guarantees that if the lhs is a tuple, its associated type is also a tuple." ), }; + if tuple_expression.elements.len() != tuple_type.len() { + return self.emit_err(TypeCheckerError::incorrect_num_tuple_elements( + tuple_expression.elements.len(), + tuple_type.len(), + input.span(), + )); + } tuple_expression.elements.iter().zip_eq(tuple_type.0.iter()).for_each(|(expression, type_)| { let identifier = match expression { Expression::Identifier(identifier) => identifier, diff --git a/errors/src/errors/type_checker/type_checker_error.rs b/errors/src/errors/type_checker/type_checker_error.rs index 98ccf0b186..bebdbe4c86 100644 --- a/errors/src/errors/type_checker/type_checker_error.rs +++ b/errors/src/errors/type_checker/type_checker_error.rs @@ -671,4 +671,11 @@ create_messages!( help: None, } + @formatted + incorrect_num_tuple_elements { + args: (identifiers: impl Display, types: impl Display), + msg: format!("Tuple length mismatch:`length {identifiers}` tuple of identifiers declared, but length `{types}` tuple of types given`"), + help: None, + } + );