mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-18 14:31:31 +03:00
add tests and remove dead code
This commit is contained in:
parent
7417496eee
commit
5ee2858b0a
@ -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_));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
13
tests/compiler/circuits/duplicate_circuit_variable.leo
Normal file
13
tests/compiler/circuits/duplicate_circuit_variable.leo
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
circuit Bar {
|
||||
x: u32,
|
||||
x: u32,
|
||||
}
|
||||
|
||||
function main() -> bool {
|
||||
return true;
|
||||
}
|
16
tests/compiler/circuits/duplicate_name_context.leo
Normal file
16
tests/compiler/circuits/duplicate_name_context.leo
Normal file
@ -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;
|
||||
}
|
20
tests/compiler/circuits/inline.leo
Normal file
20
tests/compiler/circuits/inline.leo
Normal file
@ -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;
|
||||
}
|
13
tests/compiler/circuits/inline_fail.leo
Normal file
13
tests/compiler/circuits/inline_fail.leo
Normal file
@ -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 };
|
||||
}
|
13
tests/compiler/circuits/inline_member_fail.leo
Normal file
13
tests/compiler/circuits/inline_member_fail.leo
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
circuit Foo {
|
||||
x: u8;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const y: u8 = 1;
|
||||
const a: Foo = Foo { y };
|
||||
}
|
24
tests/compiler/circuits/inline_member_pass.leo
Normal file
24
tests/compiler/circuits/inline_member_pass.leo
Normal file
@ -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;
|
||||
}
|
8
tests/compiler/circuits/inline_undefined.leo
Normal file
8
tests/compiler/circuits/inline_undefined.leo
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
function main() {
|
||||
const a: Foo = Foo { };
|
||||
}
|
6
tests/compiler/circuits/input/dummy.in
Normal file
6
tests/compiler/circuits/input/dummy.in
Normal file
@ -0,0 +1,6 @@
|
||||
[main]
|
||||
y: bool = true;
|
||||
x: bool = false;
|
||||
|
||||
[registers]
|
||||
r0: bool = true;
|
15
tests/compiler/circuits/member_variable.leo
Normal file
15
tests/compiler/circuits/member_variable.leo
Normal file
@ -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;
|
||||
}
|
13
tests/compiler/circuits/member_variable_fail.leo
Normal file
13
tests/compiler/circuits/member_variable_fail.leo
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
circuit Foo {
|
||||
x: u32;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const a: foo = Foo { x: 1u32 };
|
||||
const err = a.y;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:16\n |\n 7 | function Foo() {}\n | ^"
|
@ -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"
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: acb54d555ee391d519919827f5949bf1600d18004ce461097d062f91108563ba
|
||||
initial_ast: 347eb4d4a124a759627e26bad6ea283b07b7bc07ab35dc1576faf699c3d91e3d
|
||||
symbol_table: d522662a21597d6d4b9ca630498b48f40ad05fb289080451879c90c3530de28b
|
8
tests/expectations/compiler/compiler/circuits/inline.out
Normal file
8
tests/expectations/compiler/compiler/circuits/inline.out
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: no input
|
||||
initial_ast: c7a7ae897a82a174983ec9e81f0bcc11328fc55ea24111523131e345a363d9b8
|
||||
symbol_table: e6f85704fccd0ca0f0461ae54cb604159a5f41a2175aad6b76bd534166f1bc6b
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:17\n |\n 7 | function main() {\n | ^"
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:17\n |\n 7 | function main() {\n | ^"
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: no input
|
||||
initial_ast: 7c16a20b88d661dab8e581d47998252fc0bd2a93199f8b4945c924ade5ebae36
|
||||
symbol_table: 9eeb9c327aa691ac9126681fa2d4be149bb69621d30ac30a1432b52e42b56307
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:3:17\n |\n 3 | function main() {\n | ^"
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: 29f6139d908d390f890f04d8ee620757d29b7f71cd48c46ff65bc1e70aae840c
|
||||
initial_ast: 6e1af09bb13f26f60786c16f66286caffa646eae44511c08c2f6be46d8a1a3d1
|
||||
symbol_table: 1e3d03c1d2a087812fc00dd4c1b48174df13bc5278fd65c104c9a904644061db
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:7:17\n |\n 7 | function main() {\n | ^"
|
Loading…
Reference in New Issue
Block a user