From 5ee2858b0aed49b6d590f6d5f26c164a9b12b06c Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Wed, 22 Jun 2022 22:38:33 -1000 Subject: [PATCH] add tests and remove dead code --- .../src/type_checker/check_expressions.rs | 28 ++----------------- ...rcuit_function_namespace_conflict_fail.leo | 16 +++++++++++ .../circuits/duplicate_circuit_variable.leo | 13 +++++++++ .../circuits/duplicate_name_context.leo | 16 +++++++++++ tests/compiler/circuits/inline.leo | 20 +++++++++++++ tests/compiler/circuits/inline_fail.leo | 13 +++++++++ .../compiler/circuits/inline_member_fail.leo | 13 +++++++++ .../compiler/circuits/inline_member_pass.leo | 24 ++++++++++++++++ tests/compiler/circuits/inline_undefined.leo | 8 ++++++ tests/compiler/circuits/input/dummy.in | 6 ++++ tests/compiler/circuits/member_variable.leo | 15 ++++++++++ .../circuits/member_variable_fail.leo | 13 +++++++++ ...rcuit_function_namespace_conflict_fail.out | 5 ++++ .../circuits/duplicate_circuit_variable.out | 5 ++++ .../circuits/duplicate_name_context.out | 8 ++++++ .../compiler/compiler/circuits/inline.out | 8 ++++++ .../compiler/circuits/inline_fail.out | 5 ++++ .../compiler/circuits/inline_member_fail.out | 5 ++++ .../compiler/circuits/inline_member_pass.out | 8 ++++++ .../compiler/circuits/inline_undefined.out | 5 ++++ .../compiler/circuits/member_variable.out | 8 ++++++ .../circuits/member_variable_fail.out | 5 ++++ 22 files changed, 221 insertions(+), 26 deletions(-) create mode 100644 tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo create mode 100644 tests/compiler/circuits/duplicate_circuit_variable.leo create mode 100644 tests/compiler/circuits/duplicate_name_context.leo create mode 100644 tests/compiler/circuits/inline.leo create mode 100644 tests/compiler/circuits/inline_fail.leo create mode 100644 tests/compiler/circuits/inline_member_fail.leo create mode 100644 tests/compiler/circuits/inline_member_pass.leo create mode 100644 tests/compiler/circuits/inline_undefined.leo create mode 100644 tests/compiler/circuits/input/dummy.in create mode 100644 tests/compiler/circuits/member_variable.leo create mode 100644 tests/compiler/circuits/member_variable_fail.leo create mode 100644 tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.out create mode 100644 tests/expectations/compiler/compiler/circuits/duplicate_circuit_variable.out create mode 100644 tests/expectations/compiler/compiler/circuits/duplicate_name_context.out create mode 100644 tests/expectations/compiler/compiler/circuits/inline.out create mode 100644 tests/expectations/compiler/compiler/circuits/inline_fail.out create mode 100644 tests/expectations/compiler/compiler/circuits/inline_member_fail.out create mode 100644 tests/expectations/compiler/compiler/circuits/inline_member_pass.out create mode 100644 tests/expectations/compiler/compiler/circuits/inline_undefined.out create mode 100644 tests/expectations/compiler/compiler/circuits/member_variable.out create mode 100644 tests/expectations/compiler/compiler/circuits/member_variable_fail.out diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index cd1f62acd7..8744d7e172 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -212,26 +212,6 @@ impl<'a> ExpressionVisitorDirector<'a> for Director<'a> { // CAUTION: This implementation only allows access to core circuits. if let VisitResult::VisitChildren = self.visitor.visit_access(input) { match input { - AccessExpression::Member(access) => { - // Lookup circuit type. - if let Some(circuit) = self.visitor.symbol_table.lookup_circuit(&access.name.name) { - // Lookup circuit variable. - if let Some(member) = circuit.members.iter().find(|member| member.name() == access.name.name) { - match member { - CircuitMember::CircuitVariable(_ident, type_) => return Some(type_.clone()), - } - } else { - self.visitor.handler.emit_err( - TypeCheckerError::invalid_circuit_variable(&access.name, &access.inner, access.span()) - .into(), - ); - } - } else { - self.visitor - .handler - .emit_err(TypeCheckerError::invalid_circuit(&access.inner, access.span()).into()); - } - } AccessExpression::AssociatedFunction(access) => { // Check core circuit name and function. if let Some(core_instruction) = self.visitor.assert_core_circuit_call(&access.ty, &access.name) { @@ -279,11 +259,7 @@ impl<'a> ExpressionVisitorDirector<'a> for Director<'a> { .emit_err(TypeCheckerError::invalid_access_expression(access, access.span()).into()); } } - expr => self - .visitor - .handler - .emit_err(TypeCheckerError::invalid_access_expression(expr, expr.span()).into()), - // todo: Add support for associated constants (u8::MAX). + _expr => {} // todo: Add support for associated constants (u8::MAX). } } None @@ -670,7 +646,7 @@ impl<'a> ExpressionVisitorDirector<'a> for Director<'a> { circ.members.iter().for_each(|expected| match expected { CircuitMember::CircuitVariable(name, type_) => { // Lookup circuit variable name. - if let Some(actual) = input.members.iter().find(|member| &member.identifier == name) { + if let Some(actual) = input.members.iter().find(|member| member.identifier.name == name.name) { if let Some(expr) = &actual.expression { self.visit_expression(expr, &Some(*type_)); } diff --git a/tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo b/tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo new file mode 100644 index 0000000000..5ced98b02d --- /dev/null +++ b/tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +circuit Foo { + x: u8; +} + +function Foo() {} + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/circuits/duplicate_circuit_variable.leo b/tests/compiler/circuits/duplicate_circuit_variable.leo new file mode 100644 index 0000000000..e5946aa17f --- /dev/null +++ b/tests/compiler/circuits/duplicate_circuit_variable.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +*/ + +circuit Bar { + x: u32, + x: u32, +} + +function main() -> bool { + return true; +} diff --git a/tests/compiler/circuits/duplicate_name_context.leo b/tests/compiler/circuits/duplicate_name_context.leo new file mode 100644 index 0000000000..01b6deb400 --- /dev/null +++ b/tests/compiler/circuits/duplicate_name_context.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Pass +input_file: input/dummy.in +*/ + +circuit Bar { + b2: u32 +} + +function main(y: bool) -> bool { + const Bar: u32 = 66u32; + const k1: Bar = Bar { b2: 30u32 }; + + return y == true; +} diff --git a/tests/compiler/circuits/inline.leo b/tests/compiler/circuits/inline.leo new file mode 100644 index 0000000000..199a8031ab --- /dev/null +++ b/tests/compiler/circuits/inline.leo @@ -0,0 +1,20 @@ +/* +namespace: Compile +expectation: Pass +inputs: + - inline.in: | + [main] + x: u32 = 100; + + [registers] + r0: u32 = 0; +*/ + +circuit Foo { + x: u32 +} + +function main(x: u32) -> u32 { + let a: Foo = Foo { x: x }; + return a.x; +} diff --git a/tests/compiler/circuits/inline_fail.leo b/tests/compiler/circuits/inline_fail.leo new file mode 100644 index 0000000000..648102e956 --- /dev/null +++ b/tests/compiler/circuits/inline_fail.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +*/ + +circuit Foo { + x: u32; +} + +function main() { + // no member y in Foo + const a: Foo = Foo { y: 0u32 }; +} diff --git a/tests/compiler/circuits/inline_member_fail.leo b/tests/compiler/circuits/inline_member_fail.leo new file mode 100644 index 0000000000..abbd79d2bd --- /dev/null +++ b/tests/compiler/circuits/inline_member_fail.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +*/ + +circuit Foo { + x: u8; +} + +function main() { + const y: u8 = 1; + const a: Foo = Foo { y }; +} diff --git a/tests/compiler/circuits/inline_member_pass.leo b/tests/compiler/circuits/inline_member_pass.leo new file mode 100644 index 0000000000..4ada2e4c02 --- /dev/null +++ b/tests/compiler/circuits/inline_member_pass.leo @@ -0,0 +1,24 @@ +/* +namespace: Compile +expectation: Pass +inputs: + - inline.in: | + [main] + y: bool = true; + + [constants] + x: u8 = 10; + + [registers] + r0: bool = false; +*/ + +circuit Foo { + x: u8 +} + +function main(const x: u8, y: bool) -> bool { + const a: Foo = Foo { x }; + + return (b.x == a.x) == y; +} diff --git a/tests/compiler/circuits/inline_undefined.leo b/tests/compiler/circuits/inline_undefined.leo new file mode 100644 index 0000000000..4b75990628 --- /dev/null +++ b/tests/compiler/circuits/inline_undefined.leo @@ -0,0 +1,8 @@ +/* +namespace: Compile +expectation: Fail +*/ + +function main() { + const a: Foo = Foo { }; +} diff --git a/tests/compiler/circuits/input/dummy.in b/tests/compiler/circuits/input/dummy.in new file mode 100644 index 0000000000..d63f21e6b5 --- /dev/null +++ b/tests/compiler/circuits/input/dummy.in @@ -0,0 +1,6 @@ +[main] +y: bool = true; +x: bool = false; + +[registers] +r0: bool = true; diff --git a/tests/compiler/circuits/member_variable.leo b/tests/compiler/circuits/member_variable.leo new file mode 100644 index 0000000000..635da3da30 --- /dev/null +++ b/tests/compiler/circuits/member_variable.leo @@ -0,0 +1,15 @@ +/* +namespace: Compile +expectation: Pass +input_file: input/dummy.in +*/ + +circuit Foo { + x: u32, +} + +function main(y: bool) -> bool { + const a: Foo = Foo { x: 1u32 }; + + return (a.x == 1u32) == y; +} diff --git a/tests/compiler/circuits/member_variable_fail.leo b/tests/compiler/circuits/member_variable_fail.leo new file mode 100644 index 0000000000..0710226182 --- /dev/null +++ b/tests/compiler/circuits/member_variable_fail.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +*/ + +circuit Foo { + x: u32; +} + +function main() { + const a: foo = Foo { x: 1u32 }; + const err = a.y; +} diff --git a/tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.out b/tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.out new file mode 100644 index 0000000000..42e21bec70 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:16\n |\n 7 | function Foo() {}\n | ^" diff --git a/tests/expectations/compiler/compiler/circuits/duplicate_circuit_variable.out b/tests/expectations/compiler/compiler/circuits/duplicate_circuit_variable.out new file mode 100644 index 0000000000..7859e8194d --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/duplicate_circuit_variable.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372018]: Circuit Bar defined with more than one member with the same name.\n --> compiler-test:3:1\n |\n 3 | circuit Bar {\n 4 | x: u32,\n 5 | x: u32,\n 6 | }\n | ^\n" diff --git a/tests/expectations/compiler/compiler/circuits/duplicate_name_context.out b/tests/expectations/compiler/compiler/circuits/duplicate_name_context.out new file mode 100644 index 0000000000..c5ac2ffe3d --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/duplicate_name_context.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: acb54d555ee391d519919827f5949bf1600d18004ce461097d062f91108563ba + initial_ast: 347eb4d4a124a759627e26bad6ea283b07b7bc07ab35dc1576faf699c3d91e3d + symbol_table: d522662a21597d6d4b9ca630498b48f40ad05fb289080451879c90c3530de28b diff --git a/tests/expectations/compiler/compiler/circuits/inline.out b/tests/expectations/compiler/compiler/circuits/inline.out new file mode 100644 index 0000000000..3b1e7645d8 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/inline.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: no input + initial_ast: c7a7ae897a82a174983ec9e81f0bcc11328fc55ea24111523131e345a363d9b8 + symbol_table: e6f85704fccd0ca0f0461ae54cb604159a5f41a2175aad6b76bd534166f1bc6b diff --git a/tests/expectations/compiler/compiler/circuits/inline_fail.out b/tests/expectations/compiler/compiler/circuits/inline_fail.out new file mode 100644 index 0000000000..769bbcaee3 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/inline_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:17\n |\n 7 | function main() {\n | ^" diff --git a/tests/expectations/compiler/compiler/circuits/inline_member_fail.out b/tests/expectations/compiler/compiler/circuits/inline_member_fail.out new file mode 100644 index 0000000000..769bbcaee3 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/inline_member_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:17\n |\n 7 | function main() {\n | ^" diff --git a/tests/expectations/compiler/compiler/circuits/inline_member_pass.out b/tests/expectations/compiler/compiler/circuits/inline_member_pass.out new file mode 100644 index 0000000000..8ac8cb2e38 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/inline_member_pass.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: no input + initial_ast: 7c16a20b88d661dab8e581d47998252fc0bd2a93199f8b4945c924ade5ebae36 + symbol_table: 9eeb9c327aa691ac9126681fa2d4be149bb69621d30ac30a1432b52e42b56307 diff --git a/tests/expectations/compiler/compiler/circuits/inline_undefined.out b/tests/expectations/compiler/compiler/circuits/inline_undefined.out new file mode 100644 index 0000000000..6072996488 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/inline_undefined.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:3:17\n |\n 3 | function main() {\n | ^" diff --git a/tests/expectations/compiler/compiler/circuits/member_variable.out b/tests/expectations/compiler/compiler/circuits/member_variable.out new file mode 100644 index 0000000000..08b13f2804 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/member_variable.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: 29f6139d908d390f890f04d8ee620757d29b7f71cd48c46ff65bc1e70aae840c + initial_ast: 6e1af09bb13f26f60786c16f66286caffa646eae44511c08c2f6be46d8a1a3d1 + symbol_table: 1e3d03c1d2a087812fc00dd4c1b48174df13bc5278fd65c104c9a904644061db diff --git a/tests/expectations/compiler/compiler/circuits/member_variable_fail.out b/tests/expectations/compiler/compiler/circuits/member_variable_fail.out new file mode 100644 index 0000000000..769bbcaee3 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/member_variable_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:17\n |\n 7 | function main() {\n | ^"