adds check for already existing functions

This commit is contained in:
damirka 2021-04-07 19:39:53 +03:00
parent e31bace4cb
commit f55e880c43
2 changed files with 14 additions and 1 deletions

View File

@ -172,6 +172,13 @@ impl AsgConvertError {
)
}
pub fn duplicate_function_definition(name: &str, span: &Span) -> Self {
Self::new_from_span(
format!("duplicate definition, function with name \"{}\" already exists", name),
span,
)
}
pub fn index_into_non_tuple(name: &str, span: &Span) -> Self {
Self::new_from_span(format!("failed to index into non-tuple '{}'", name), span)
}

View File

@ -266,7 +266,13 @@ impl<'a> Program<'a> {
asg_function.fill_from_ast(function)?;
functions.insert(name.name.to_string(), asg_function);
let name = name.name.to_string();
if functions.contains_key(&name) {
return Err(AsgConvertError::duplicate_function_definition(&name, &function.span));
}
functions.insert(name, asg_function);
}
let mut circuits = IndexMap::new();