the identifiers differ, change it to name

This commit is contained in:
gluax 2021-07-02 18:29:48 -07:00
parent 6022f42fa5
commit a496841563
6 changed files with 19 additions and 5 deletions

View File

@ -131,7 +131,7 @@ pub enum ConstValue<'a> {
// compounds
Tuple(Vec<ConstValue<'a>>),
Array(Vec<ConstValue<'a>>),
Circuit(&'a Circuit<'a>, IndexMap<Identifier, ConstValue<'a>>),
Circuit(&'a Circuit<'a>, IndexMap<String, (Identifier, ConstValue<'a>)>),
}
macro_rules! const_int_op {

View File

@ -176,6 +176,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
} else {
None
};
if let Some(expected_len) = expected_len {
if let Some(length) = length {
if length != expected_len {

View File

@ -85,7 +85,10 @@ impl<'a> ExpressionNode<'a> for CircuitAccessExpression<'a> {
fn const_value(&self) -> Option<ConstValue<'a>> {
match self.target.get()?.const_value()? {
ConstValue::Circuit(_, members) => members.get(&self.member).cloned(),
ConstValue::Circuit(_, members) => {
let (_, const_value) = members.get(&self.member.name.to_string())?.clone();
Some(const_value)
}
_ => None,
}
}

View File

@ -73,8 +73,13 @@ impl<'a> ExpressionNode<'a> for CircuitInitExpression<'a> {
fn const_value(&self) -> Option<ConstValue<'a>> {
let mut members = IndexMap::new();
for (identifier, member) in self.values.iter() {
members.insert(identifier.clone(), member.get().const_value()?);
// insert by name because accessmembers identifiers are different.
members.insert(
identifier.name.to_string(),
(identifier.clone(), member.get().const_value()?),
);
}
// Store circuit as well for get_type.
Some(ConstValue::Circuit(self.circuit.get(), members))
}

View File

@ -77,7 +77,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
),
ConstValue::Circuit(circuit, members) => {
let mut constrained_members = Vec::new();
for (identifier, member) in members.iter() {
for (_, (identifier, member)) in members.iter() {
constrained_members.push(ConstrainedCircuitMember(
identifier.clone(),
self.enforce_const_value(cs, member, span)?,

View File

@ -5,6 +5,10 @@ input_file:
- input/complex_access.in
*/
circuit Circ {
f: u32
}
function main (a: [u8; 8], b: u32, c: [[u8; 3]; 3], d: [(u8, u32); 1], e: [u8; (3, 4)] ) -> bool {
a[0..3][b] = 93;
a[2..6][1] = 87;
@ -16,6 +20,7 @@ function main (a: [u8; 8], b: u32, c: [[u8; 3]; 3], d: [(u8, u32); 1], e: [u8; (
c[0..2][0] = [1u8; 3];
c[1..][1][1..2][0] = 126;
c[1..][0] = [42, 43, 44];
c[Circ {f: 0}.f..1][0][0] += 2;
d[..1][0].1 = 1;
@ -24,7 +29,7 @@ function main (a: [u8; 8], b: u32, c: [[u8; 3]; 3], d: [(u8, u32); 1], e: [u8; (
return
a == [200u8, 93, 42, 174, 5, 6, 43, 8]
&& c == [[1u8, 1, 1], [42, 43, 44], [7, 126, 9]]
&& c == [[3u8, 1, 1], [42, 43, 44], [7, 126, 9]]
&& d == [(0u8, 1u32)]
&& e == [[33u8, 22, 22, 22], [0, 0, 0, 0], [0, 0, 0, 0]];
}