mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-02 23:07:27 +03:00
Merge pull request #837 from AleoHQ/bug-duplicate-functions
Adds error when function defined more than once
This commit is contained in:
commit
bd7ec477c9
@ -172,6 +172,13 @@ impl AsgConvertError {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn duplicate_function_definition(name: &str, span: &Span) -> Self {
|
||||
Self::new_from_span(
|
||||
format!("a function named \"{}\" already exists in this scope", 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)
|
||||
}
|
||||
|
@ -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();
|
||||
|
7
compiler/tests/function/duplicate_definition.leo
Normal file
7
compiler/tests/function/duplicate_definition.leo
Normal file
@ -0,0 +1,7 @@
|
||||
function main() {
|
||||
console.log("{}", 1u8);
|
||||
}
|
||||
|
||||
function main() {
|
||||
console.log("{}", 2u8);
|
||||
}
|
@ -211,3 +211,11 @@ fn test_array_params_direct_call() {
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_function_definition() {
|
||||
let program_string = include_str!("duplicate_definition.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user