mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
add dynamic check errors for circuits 2
This commit is contained in:
parent
973e2a6afc
commit
e19616b4e5
@ -138,9 +138,9 @@ fn test_member_static_function_undefined() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_mutate_function_fail() {
|
fn test_mutate_function_fail() {
|
||||||
let bytes = include_bytes!("mut_function_fail.leo");
|
let bytes = include_bytes!("mut_function_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]
|
||||||
@ -178,9 +178,9 @@ fn test_mutate_self_static_function_fail() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_mutate_static_function_fail() {
|
fn test_mutate_static_function_fail() {
|
||||||
let bytes = include_bytes!("mut_static_function_fail.leo");
|
let bytes = include_bytes!("mut_static_function_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]
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
circuit Foo {
|
circuit Foo {
|
||||||
|
a: u8,
|
||||||
|
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1039,7 +1039,11 @@ impl Frame {
|
|||||||
|
|
||||||
// Check the length of the circuit members.
|
// Check the length of the circuit members.
|
||||||
if circuit_type.variables.len() != members.len() {
|
if circuit_type.variables.len() != members.len() {
|
||||||
unimplemented!("Number of circuit arguments invalid")
|
return Err(FrameError::num_variables(
|
||||||
|
circuit_type.variables.len(),
|
||||||
|
members.len(),
|
||||||
|
span,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert members are circuit type member types.
|
// Assert members are circuit type member types.
|
||||||
@ -1224,7 +1228,7 @@ impl Frame {
|
|||||||
|
|
||||||
// Check the length of arguments
|
// Check the length of arguments
|
||||||
if function_type.inputs.len() != inputs.len() {
|
if function_type.inputs.len() != inputs.len() {
|
||||||
unimplemented!("Number of function arguments invalid")
|
return Err(FrameError::num_inputs(function_type.inputs.len(), inputs.len(), span));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert function inputs are correct types.
|
// Assert function inputs are correct types.
|
||||||
|
@ -69,7 +69,7 @@ impl FrameError {
|
|||||||
/// Attempted to call non-static member using `::`.
|
/// Attempted to call non-static member using `::`.
|
||||||
///
|
///
|
||||||
pub fn invalid_member_access(identifier: &Identifier) -> Self {
|
pub fn invalid_member_access(identifier: &Identifier) -> Self {
|
||||||
let message = format!("non-static member `{}` must be accessed using `.` syntax", identifier);
|
let message = format!("non-static member `{}` must be accessed using `.` syntax.", identifier);
|
||||||
|
|
||||||
Self::new_from_span(message, identifier.span.to_owned())
|
Self::new_from_span(message, identifier.span.to_owned())
|
||||||
}
|
}
|
||||||
@ -78,11 +78,32 @@ impl FrameError {
|
|||||||
/// Attempted to call static member using `.`.
|
/// Attempted to call static member using `.`.
|
||||||
///
|
///
|
||||||
pub fn invalid_static_access(identifier: &Identifier) -> Self {
|
pub fn invalid_static_access(identifier: &Identifier) -> Self {
|
||||||
let message = format!("static member `{}` must be accessed using `::` syntax", identifier);
|
let message = format!("static member `{}` must be accessed using `::` syntax.", identifier);
|
||||||
|
|
||||||
Self::new_from_span(message, identifier.span.to_owned())
|
Self::new_from_span(message, identifier.span.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Attempted to call a function with the incorrect number of inputs.
|
||||||
|
///
|
||||||
|
pub fn num_inputs(expected: usize, actual: usize, span: &Span) -> Self {
|
||||||
|
let message = format!(
|
||||||
|
"Function expected {} input variables, found {} inputs.",
|
||||||
|
expected, actual
|
||||||
|
);
|
||||||
|
|
||||||
|
Self::new_from_span(message, span.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Attempted to create a circuit with the incorrect number of member variables.
|
||||||
|
///
|
||||||
|
pub fn num_variables(expected: usize, actual: usize, span: &Span) -> Self {
|
||||||
|
let message = format!("Circuit expected {} variables, found {} variables.", expected, actual);
|
||||||
|
|
||||||
|
Self::new_from_span(message, span.clone())
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Attempted to call a circuit type that is not defined in the current context.
|
/// Attempted to call a circuit type that is not defined in the current context.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user