Skip to content

Commit

Permalink
create error for tuple length mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-schott committed Sep 25, 2023
1 parent e803375 commit c15ca6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/passes/src/type_checking/check_statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions errors/src/errors/type_checker/type_checker_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

);

0 comments on commit c15ca6c

Please sign in to comment.