mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-28 01:01:53 +03:00
add dynamic check errors for functions
This commit is contained in:
parent
e19616b4e5
commit
22d6c98c77
@ -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");
|
||||
|
@ -14,8 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
|
||||
|
@ -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]
|
||||
|
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
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]
|
||||
|
@ -1143,11 +1143,10 @@ impl Frame {
|
||||
/// Returns a `FunctionType` given a function identifier.
|
||||
///
|
||||
fn parse_program_function(&mut self, identifier: &Identifier, _span: &Span) -> Result<FunctionType, FrameError> {
|
||||
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)
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user