add dynamic check errors for functions

This commit is contained in:
collin 2020-10-24 16:50:07 -07:00
parent e19616b4e5
commit 22d6c98c77
6 changed files with 26 additions and 31 deletions

View File

@ -23,7 +23,6 @@ use crate::{
parse_program_with_input, parse_program_with_input,
EdwardsTestCompiler, EdwardsTestCompiler,
}; };
use leo_compiler::errors::{BooleanError, CompilerError, ExpressionError, FunctionError, StatementError};
pub fn output_true(program: EdwardsTestCompiler) { pub fn output_true(program: EdwardsTestCompiler) {
let expected = include_bytes!("output/registers_true.out"); let expected = include_bytes!("output/registers_true.out");

View File

@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License // 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/>. // 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 crate::{assert_satisfied, expect_compiler_error, expect_dynamic_check_error, parse_program};
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError};
// Expressions // Expressions

View File

@ -17,22 +17,13 @@
use crate::{ use crate::{
assert_satisfied, assert_satisfied,
expect_compiler_error, expect_compiler_error,
expect_dynamic_check_error,
get_output, get_output,
parse_program, parse_program,
parse_program_with_input, parse_program_with_input,
EdwardsTestCompiler,
}; };
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError}; 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] #[test]
fn test_empty() { fn test_empty() {
let bytes = include_bytes!("empty.leo"); let bytes = include_bytes!("empty.leo");
@ -129,9 +120,9 @@ fn test_scope_fail() {
#[test] #[test]
fn test_undefined() { fn test_undefined() {
let bytes = include_bytes!("undefined.leo"); 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] #[test]
@ -147,9 +138,9 @@ fn test_value_unchanged() {
#[test] #[test]
fn test_return_array_nested_fail() { fn test_return_array_nested_fail() {
let bytes = include_bytes!("return_array_nested_fail.leo"); 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] #[test]
@ -163,9 +154,9 @@ fn test_return_array_nested_pass() {
#[test] #[test]
fn test_return_array_tuple_fail() { fn test_return_array_tuple_fail() {
let bytes = include_bytes!("return_array_tuple_fail.leo"); 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] #[test]

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // 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/>. // 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; use leo_typed::InputValue;
#[test] #[test]
@ -92,17 +92,17 @@ fn test_circuit_variable_mut() {
#[test] #[test]
fn test_circuit_function_mut() { fn test_circuit_function_mut() {
let bytes = include_bytes!("circuit_function_mut.leo"); 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] #[test]
fn test_circuit_static_function_mut() { fn test_circuit_static_function_mut() {
let bytes = include_bytes!("circuit_static_function_mut.leo"); 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] #[test]

View File

@ -1143,11 +1143,10 @@ impl Frame {
/// Returns a `FunctionType` given a function identifier. /// Returns a `FunctionType` given a function identifier.
/// ///
fn parse_program_function(&mut self, identifier: &Identifier, _span: &Span) -> Result<FunctionType, FrameError> { fn parse_program_function(&mut self, identifier: &Identifier, _span: &Span) -> Result<FunctionType, FrameError> {
Ok(self self.user_defined_types
.user_defined_types
.get_function(&identifier.name) .get_function(&identifier.name)
.unwrap() .map(|function_type| function_type.to_owned())
.to_owned()) .ok_or_else(|| FrameError::undefined_function(identifier))
} }
/// ///
@ -1715,9 +1714,7 @@ impl TypeVariablePairs {
} }
// Compare the array element types. // Compare the array element types.
self.push_pairs(left_type_flat, right_type_flat, span); self.push_pairs(left_type_flat, right_type_flat, span)
Ok(())
} }
/// ///

View File

@ -121,4 +121,13 @@ impl FrameError {
Self::new_from_span(message, identifier.span.to_owned()) 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())
}
} }