diff --git a/compiler/tests/boolean/mod.rs b/compiler/tests/boolean/mod.rs
index 7d9fcd9d08..6901c2a15b 100644
--- a/compiler/tests/boolean/mod.rs
+++ b/compiler/tests/boolean/mod.rs
@@ -23,7 +23,6 @@ use crate::{
parse_program_with_input,
EdwardsTestCompiler,
};
-use leo_compiler::errors::{BooleanError, CompilerError, ExpressionError, FunctionError, StatementError};
pub fn output_true(program: EdwardsTestCompiler) {
let expected = include_bytes!("output/registers_true.out");
diff --git a/compiler/tests/circuits/mod.rs b/compiler/tests/circuits/mod.rs
index 3935fd8dcc..79cb5bc1c2 100644
--- a/compiler/tests/circuits/mod.rs
+++ b/compiler/tests/circuits/mod.rs
@@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see .
-use crate::{assert_satisfied, expect_compiler_error, expect_dynamic_check_error, parse_program, EdwardsTestCompiler};
-use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError};
+use crate::{assert_satisfied, expect_compiler_error, expect_dynamic_check_error, parse_program};
// Expressions
diff --git a/compiler/tests/function/mod.rs b/compiler/tests/function/mod.rs
index d5a3c3548b..69e9d1b980 100644
--- a/compiler/tests/function/mod.rs
+++ b/compiler/tests/function/mod.rs
@@ -17,22 +17,13 @@
use crate::{
assert_satisfied,
expect_compiler_error,
+ expect_dynamic_check_error,
get_output,
parse_program,
parse_program_with_input,
- EdwardsTestCompiler,
};
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError};
-fn expect_undefined_identifier(program: EdwardsTestCompiler) {
- match expect_compiler_error(program) {
- CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
- ExpressionError::Error(_),
- ))) => {}
- error => panic!("Expected function undefined, got {}", error),
- }
-}
-
#[test]
fn test_empty() {
let bytes = include_bytes!("empty.leo");
@@ -129,9 +120,9 @@ fn test_scope_fail() {
#[test]
fn test_undefined() {
let bytes = include_bytes!("undefined.leo");
- let program = parse_program(bytes).unwrap();
+ let error = parse_program(bytes).err().unwrap();
- expect_undefined_identifier(program);
+ expect_dynamic_check_error(error);
}
#[test]
@@ -147,9 +138,9 @@ fn test_value_unchanged() {
#[test]
fn test_return_array_nested_fail() {
let bytes = include_bytes!("return_array_nested_fail.leo");
- let program = parse_program(bytes).unwrap();
+ let error = parse_program(bytes).err().unwrap();
- expect_compiler_error(program);
+ expect_dynamic_check_error(error);
}
#[test]
@@ -163,9 +154,9 @@ fn test_return_array_nested_pass() {
#[test]
fn test_return_array_tuple_fail() {
let bytes = include_bytes!("return_array_tuple_fail.leo");
- let program = parse_program(bytes).unwrap();
+ let error = parse_program(bytes).err().unwrap();
- expect_compiler_error(program);
+ expect_dynamic_check_error(error);
}
#[test]
diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs
index ea380447bf..c36cd10b14 100644
--- a/compiler/tests/mutability/mod.rs
+++ b/compiler/tests/mutability/mod.rs
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see .
-use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program};
+use crate::{assert_satisfied, expect_compiler_error, expect_dynamic_check_error, generate_main_input, parse_program};
use leo_typed::InputValue;
#[test]
@@ -92,17 +92,17 @@ fn test_circuit_variable_mut() {
#[test]
fn test_circuit_function_mut() {
let bytes = include_bytes!("circuit_function_mut.leo");
- let program = parse_program(bytes).unwrap();
+ let error = parse_program(bytes).err().unwrap();
- expect_compiler_error(program);
+ expect_dynamic_check_error(error);
}
#[test]
fn test_circuit_static_function_mut() {
let bytes = include_bytes!("circuit_static_function_mut.leo");
- let program = parse_program(bytes).unwrap();
+ let error = parse_program(bytes).err().unwrap();
- expect_compiler_error(program);
+ expect_dynamic_check_error(error);
}
#[test]
diff --git a/dynamic-check/src/dynamic_check.rs b/dynamic-check/src/dynamic_check.rs
index b0109b3a6b..4aa6a2654f 100644
--- a/dynamic-check/src/dynamic_check.rs
+++ b/dynamic-check/src/dynamic_check.rs
@@ -1143,11 +1143,10 @@ impl Frame {
/// Returns a `FunctionType` given a function identifier.
///
fn parse_program_function(&mut self, identifier: &Identifier, _span: &Span) -> Result {
- Ok(self
- .user_defined_types
+ self.user_defined_types
.get_function(&identifier.name)
- .unwrap()
- .to_owned())
+ .map(|function_type| function_type.to_owned())
+ .ok_or_else(|| FrameError::undefined_function(identifier))
}
///
@@ -1715,9 +1714,7 @@ impl TypeVariablePairs {
}
// Compare the array element types.
- self.push_pairs(left_type_flat, right_type_flat, span);
-
- Ok(())
+ self.push_pairs(left_type_flat, right_type_flat, span)
}
///
diff --git a/dynamic-check/src/errors/frame.rs b/dynamic-check/src/errors/frame.rs
index 07d1e98e0d..5bc248a47a 100644
--- a/dynamic-check/src/errors/frame.rs
+++ b/dynamic-check/src/errors/frame.rs
@@ -121,4 +121,13 @@ impl FrameError {
Self::new_from_span(message, identifier.span.to_owned())
}
+
+ ///
+ /// Attempted to call a function that is not defined in the current context.
+ ///
+ pub fn undefined_function(identifier: &Identifier) -> Self {
+ let message = format!("The function `{}` is not defined.", identifier);
+
+ Self::new_from_span(message, identifier.span.to_owned())
+ }
}