merge master, add a parser test to try and improve code coverage

This commit is contained in:
gluax 2021-05-07 13:34:10 -04:00
commit f32a1e9ddb
149 changed files with 792 additions and 520 deletions

View File

@ -172,6 +172,16 @@ impl AsgConvertError {
)
}
pub fn invalid_const_assign(name: &str, span: &Span) -> Self {
Self::new_from_span(
format!(
"failed to create const variable(s) '{}' with non constant values.",
name
),
span,
)
}
pub fn duplicate_function_definition(name: &str, span: &Span) -> Self {
Self::new_from_span(
format!("a function named \"{}\" already exists in this scope", name),

View File

@ -75,6 +75,17 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?;
if matches!(statement.declaration_type, leo_ast::Declare::Const) && !value.is_consty() {
let var_names = statement
.variable_names
.iter()
.map(ToString::to_string)
.collect::<Vec<String>>()
.join(" ,");
return Err(AsgConvertError::invalid_const_assign(&var_names, &statement.span));
}
let type_ = type_.or_else(|| value.get_type());
let mut output_types = vec![];

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function bar() {}
}

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function bar() {}

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function bar() {}

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function set_a(self, new: u8) {
self.a = new;

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
f: u32,
f: u32;
function bar() -> u32 {
return f;

View File

@ -1,6 +1,6 @@
// Circuits are immutable by default.
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -2,7 +2,7 @@ function main(s: bool, c: address) {
const a = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
const b = aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r;
const r = s? a: b;
let r = s ? a: b;
console.assert(r == c);
}

View File

@ -1,4 +1,4 @@
function main () {
let b = false;
const b = false;
const a = !b;
}

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u32,
a: u32;
}
circuit Bar {

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32,
x: u32;
function add_x(self, y: u32) -> u32 {
return self.x + y;

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32,
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
foo: u32,
foo: u32;
function bar() -> u32 {
return 1u32;

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function set_a(mut self, new: u8) {
self.a = new;

View File

@ -5,7 +5,7 @@ function main() {
}
circuit Foo {
a: u32
a: u32;
function bar(mut self) {
if true {

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
}
function main() {

View File

@ -1,14 +1,14 @@
circuit PedersenHash {
parameters: [u32; 512]
parameters: [u32; 512];
function new(parameters: [u32; 512]) -> Self {
function new(const parameters: [u32; 512]) -> Self {
return Self { parameters: parameters };
}
function hash(self, bits: [bool; 512]) -> u32 {
function hash(self, const bits: [bool; 512]) -> u32 {
let digest: u32 = 0;
for i in 0..512 {
const base = bits[i] ? self.parameters[i] : 0u32;
let base = bits[i] ? self.parameters[i] : 0u32;
digest += base;
}
return digest;

View File

@ -1,5 +1,5 @@
circuit Foo {
f: u32,
f: u32;
function bar(self) -> u32 {
return self.f;

View File

@ -1,7 +1,7 @@
import core.unstable.blake2s.Blake2s;
function main(seed: [u8; 32], message: [u8; 32], expected: [u8; 32]) {
const actual = Blake2s::hash(seed, message);
let actual = Blake2s::hash(seed, message);
console.assert(expected == actual);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: field, b: field, c: field) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -58,8 +58,8 @@ fn test_imports() {
let mut imports = crate::mocked_resolver(&context);
let test_import = r#"
circuit Point {
x: u32
y: u32
x: u32;
y: u32;
}
function foo() -> u32 {

View File

@ -1,3 +1,3 @@
function main(a: group) {
const b = a;
let b = a;
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: group, b: group, c: group) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,3 +1,3 @@
circuit Bat {
t: u32
t: u32;
}

View File

@ -1,7 +1,7 @@
circuit Baz {
z: u32
z: u32;
}
circuit Bazzar {
a: u32
a: u32;
}

View File

@ -1,3 +1,3 @@
circuit Bar {
r: u32
r: u32;
}

View File

@ -1,3 +1,3 @@
circuit Car {
c: u32
c: u32;
}

View File

@ -1,6 +1,6 @@
circuit Point {
x: u32
y: u32
x: u32;
y: u32;
}
function foo() -> u32 {

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i128, b: i128, c: i128) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i16, b: i16, c: i16) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i32, b: i32, c: i32) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i64, b: i64, c: i64) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i8, b: i8, c: i8) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u128, b: u128, c: u128) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u16, b: u16, c: u16) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u32, b: u32, c: u32) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u64, b: u64, c: u64) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u8, b: u8, c: u8) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,6 +1,6 @@
// Adding the `mut` keyword makes a circuit variable mutable.
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,6 +1,6 @@
// Adding the `mut` keyword makes a circuit variable mutable.
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
function main () {
let x = 2u8;
let y = x;
const z = y / 2u8;
let z = y / 2u8;
}

View File

@ -1,6 +1,6 @@
// Swap two elements of an array.
function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] {
const t = a[i];
let t = a[i];
a[i] = a[j];
a[j] = t;
return a;
@ -11,7 +11,7 @@ function main() {
const expected: [u32; 2] = [1, 0];
// Do swap.
const actual = swap(arr, 0, 1);
let actual = swap(arr, 0, 1);
// Check result.
for i in 0..2 {

View File

@ -7,7 +7,7 @@ function main(a: bool) {
}
}
const r: u32 = a ? 6 : 0;
let r: u32 = a ? 6 : 0;
console.assert(r == b);
}

View File

@ -1,5 +1,5 @@
function main(a: bool, b: bool) {
const c = a ? true : false;
let c = a ? true : false;
const d = c == b;
let d = c == b;
}

View File

@ -2,7 +2,7 @@ function main(s: bool, c: address) {
const a = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
const b = aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r;
const r = s? a: b;
let r = s ? a: b;
console.assert(r == c);
}

View File

@ -1,4 +1,4 @@
function main () {
let b = false;
const b = false;
const a = !b;
}

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
function new() -> Self {
let new: Self = Self {

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
function new() -> Self {
let new: Self = Self {

View File

@ -1,6 +1,6 @@
circuit Foo {
f: u8,
y: (u8, u8),
f: u8;
y: (u8, u8);
function z (mut self) -> u16 {
self.y.0 += 1u8;

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function use_a(const self) -> u8 {
return self.a + 1;

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function set_a(const self, new: u8) {
self.a = new;

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u32,
a: u32;
}
circuit Bar {

View File

@ -1,5 +1,5 @@
circuit Bar {
b2: u32
b2: u32;
function add_five(z:u32) -> u32 {
return z+5u32;

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u8
x: u8;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u8
x: u8;
function new(x: u8) -> Self {
return Self { x };

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32,
x: u32;
function echo(self) -> u32 {
return self.x;

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32,
x: u32;
function add_x(self, y: u32) -> u32 {
return self.x + y;

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32,
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
foo: u32,
foo: u32;
function bar() -> u32 {
return 1u32;

View File

@ -1,5 +1,5 @@
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function bar() {}
}

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function bar() {}

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function bar() {}

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function set_a(mut self, new: u8) {
self.a = new;

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function set_a(mut self, condition: bool, new: u8) {
if condition {

View File

@ -5,7 +5,7 @@ function main() {
}
circuit Foo {
a: u32
a: u32;
function bar(mut self) {
if true {

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
function set_a(self, new: u8) {
self.a = new;

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit Foo {
a: u8,
a: u8;
}
function main() {

View File

@ -1,5 +1,5 @@
circuit TestMe {
x: u8,
x: u8;
function test_me(mut self) -> u8 {
self.x += 1;

View File

@ -1,14 +1,14 @@
circuit PedersenHash {
parameters: [u32; 512]
parameters: [u32; 512];
function new(parameters: [u32; 512]) -> Self {
function new(const parameters: [u32; 512]) -> Self {
return Self { parameters: parameters };
}
function hash(self, bits: [bool; 512]) -> u32 {
function hash(self, const bits: [bool; 512]) -> u32 {
let digest: u32 = 0;
for i in 0..512 {
const base = bits[i] ? self.parameters[i] : 0u32;
let base = bits[i] ? self.parameters[i] : 0u32;
digest += base;
}
return digest;

View File

@ -1,5 +1,5 @@
circuit Foo {
f: u32,
f: u32;
function bar(self) -> u32 {
return self.f;

View File

@ -1,5 +1,5 @@
circuit Foo {
f: u32,
f: u32;
function bar() -> u32 {
return f;

View File

@ -1,7 +1,7 @@
import core.unstable.blake2s.Blake2s;
function main(seed: [u8; 32], message: [u8; 32], expected: [u8; 32]) {
const actual = Blake2s::hash(seed, message);
let actual = Blake2s::hash(seed, message);
console.assert(expected == actual);
}

View File

@ -10,8 +10,8 @@ const foo = Foo { width: 10, height: 20 };
const uno = uno();
circuit Foo {
width: u32,
height: u32,
width: u32;
height: u32;
}
function uno() -> u32 {

View File

@ -1,3 +1,3 @@
circuit Bat {
t: u32
t: u32;
}

View File

@ -1,9 +1,9 @@
circuit Baz {
z: u32
z: u32;
}
circuit Bazzar {
a: u32
a: u32;
}
const ONE: u8 = 1;

View File

@ -1,3 +1,3 @@
circuit Bar {
r: u32
r: u32;
}

View File

@ -1,3 +1,3 @@
circuit Car {
c: u32
c: u32;
}

View File

@ -1,6 +1,6 @@
circuit Point {
x: u32
y: u32
x: u32;
y: u32;
}
function foo() -> u32 {

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i128, b: i128, c: i128) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i16, b: i16, c: i16) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i32, b: i32, c: i32) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i64, b: i64, c: i64) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: i8, b: i8, c: i8) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u128, b: u128, c: u128) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u16, b: u16, c: u16) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u32, b: u32, c: u32) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u64, b: u64, c: u64) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,5 +1,5 @@
function main(s: bool, a: u8, b: u8, c: u8) {
const r = s ? a : b;
let r = s ? a : b;
console.assert(r == c);
}

View File

@ -1,6 +1,6 @@
// Circuits are immutable by default.
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,6 +1,6 @@
// Adding the `mut` keyword makes a circuit variable mutable.
circuit Foo {
x: u32
x: u32;
}
function main() {

View File

@ -1,6 +1,6 @@
// Adding the `mut` keyword makes a circuit variable mutable.
circuit Foo {
x: u32
x: u32;
}
function main() {

Some files were not shown because too many files have changed in this diff Show More