From 350430f66cf0fa1bf544532e61cfd3fccf242149 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 30 May 2023 18:27:36 +0200 Subject: [PATCH] add more tests --- .../assembly/unallowed_type_in_assignment.zok | 6 ++++++ .../unallowed_type_in_constrained_assignment.zok | 6 ++++++ zokrates_core/src/semantics.rs | 4 ++-- .../tests/assembly/composite_assignment.json | 16 ++++++++++++++++ .../tests/assembly/composite_assignment.zok | 7 +++++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_assignment.zok create mode 100644 zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_constrained_assignment.zok create mode 100644 zokrates_core_test/tests/tests/assembly/composite_assignment.json create mode 100644 zokrates_core_test/tests/tests/assembly/composite_assignment.zok diff --git a/zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_assignment.zok b/zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_assignment.zok new file mode 100644 index 00000000..d3c1c232 --- /dev/null +++ b/zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_assignment.zok @@ -0,0 +1,6 @@ +def main(bool a) { + bool mut b = false; + asm { + b <-- a; + } +} \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_constrained_assignment.zok b/zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_constrained_assignment.zok new file mode 100644 index 00000000..f17a895f --- /dev/null +++ b/zokrates_cli/examples/compile_errors/assembly/unallowed_type_in_constrained_assignment.zok @@ -0,0 +1,6 @@ +def main() { + field[2] mut a = [0; 2]; + asm { + a <== [1, 2]; + } +} \ No newline at end of file diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 05776e87..77a08eb2 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1834,7 +1834,7 @@ impl<'ast, T: Field> Checker<'ast, T> { } ty => Err(ErrorInner { span: Some(span), - message: format!("Assignee must be a field element, found {}", ty), + message: format!("Assignee must be of type field, found {}", ty), }), }, false => { @@ -1849,7 +1849,7 @@ impl<'ast, T: Field> Checker<'ast, T> { }, false => Err(ErrorInner { span: Some(span), - message: "Assignee must be a field element or a composite type of field elements".to_string(), + message: "Assignee must be of type field or a composite type of field elements".to_string(), }) } } diff --git a/zokrates_core_test/tests/tests/assembly/composite_assignment.json b/zokrates_core_test/tests/tests/assembly/composite_assignment.json new file mode 100644 index 00000000..7fce10f1 --- /dev/null +++ b/zokrates_core_test/tests/tests/assembly/composite_assignment.json @@ -0,0 +1,16 @@ +{ + "curves": ["Bn128"], + "max_constraint_count": 1, + "tests": [ + { + "input": { + "values": ["2", "2", "4"] + }, + "output": { + "Ok": { + "value": [] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/assembly/composite_assignment.zok b/zokrates_core_test/tests/tests/assembly/composite_assignment.zok new file mode 100644 index 00000000..9bf3af9f --- /dev/null +++ b/zokrates_core_test/tests/tests/assembly/composite_assignment.zok @@ -0,0 +1,7 @@ +def main(field a, field b, field c) { + field[2] mut out = [0; 2]; + asm { + out <-- [a, b]; + out[0] * out[1] === c; + } +} \ No newline at end of file