mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-21 12:07:56 +03:00
infer loop variable types + fix pedersen example
This commit is contained in:
parent
60d243fd43
commit
cec3a40eb1
@ -2,11 +2,11 @@ circuit PedersenHash {
|
||||
parameters: [group; 256],
|
||||
|
||||
// Instantiates a Pedersen hash circuit
|
||||
static function new(parameters: [group; 256]) -> Self {
|
||||
function new(parameters: [group; 256]) -> Self {
|
||||
return Self { parameters: parameters }
|
||||
}
|
||||
|
||||
function hash(bits: [bool; 256]) -> group {
|
||||
function hash(self, bits: [bool; 256]) -> group {
|
||||
let mut digest: group = 0;
|
||||
for i in 0..256 {
|
||||
if bits[i] {
|
||||
|
@ -426,8 +426,8 @@ impl Frame {
|
||||
let _expect_none = self.insert_variable(statement.variable.name.to_owned(), u32_type.clone(), &statement.span);
|
||||
|
||||
// Parse `from` and `to` expressions.
|
||||
let from_type = self.parse_expression(&statement.start)?;
|
||||
let to_type = self.parse_expression(&statement.stop)?;
|
||||
let from_type = self.parse_index(&statement.start)?;
|
||||
let to_type = self.parse_index(&statement.stop)?;
|
||||
|
||||
// Assert `from` and `to` types are a u32 or implicit.
|
||||
self.assert_equal(u32_type.clone(), from_type, &statement.span);
|
||||
|
@ -17,6 +17,7 @@
|
||||
pub mod arrays;
|
||||
pub mod circuits;
|
||||
pub mod functions;
|
||||
pub mod statements;
|
||||
pub mod tuples;
|
||||
pub mod variables;
|
||||
|
||||
|
7
type-inference/tests/statements/array_loop_implicit.leo
Normal file
7
type-inference/tests/statements/array_loop_implicit.leo
Normal file
@ -0,0 +1,7 @@
|
||||
function main() {
|
||||
let a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
for i in 0..10 {
|
||||
console.log("{}", a[i]);
|
||||
}
|
||||
}
|
5
type-inference/tests/statements/loop_implicit.leo
Normal file
5
type-inference/tests/statements/loop_implicit.leo
Normal file
@ -0,0 +1,5 @@
|
||||
function main() {
|
||||
for i in 0..10 {
|
||||
console.log("{}", i);
|
||||
}
|
||||
}
|
35
type-inference/tests/statements/mod.rs
Normal file
35
type-inference/tests/statements/mod.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::TestTypeInference;
|
||||
|
||||
#[test]
|
||||
fn test_loop_implicit() {
|
||||
let program_string = include_str!("loop_implicit.leo");
|
||||
|
||||
let check = TestTypeInference::new(program_string);
|
||||
|
||||
check.check();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_loop_implicit() {
|
||||
let program_string = include_str!("array_loop_implicit.leo");
|
||||
|
||||
let check = TestTypeInference::new(program_string);
|
||||
|
||||
check.check();
|
||||
}
|
Loading…
Reference in New Issue
Block a user