mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 03:33:44 +03:00
Merge pull request #493 from AleoHQ/fix/self-access-scope
fix accessing self variable inside nested scope bug
This commit is contained in:
commit
878f0a8461
@ -36,6 +36,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
indicator: &Boolean,
|
||||
block: Block,
|
||||
return_type: Option<Type>,
|
||||
declared_circuit_reference: &str,
|
||||
mut_self: bool,
|
||||
) -> StatementResult<Vec<IndicatorAndConstrainedValue<F, G>>> {
|
||||
let mut results = Vec::with_capacity(block.statements.len());
|
||||
@ -48,7 +49,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
indicator,
|
||||
statement,
|
||||
return_type.clone(),
|
||||
"",
|
||||
declared_circuit_reference,
|
||||
mut_self,
|
||||
)?;
|
||||
|
||||
|
@ -52,6 +52,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
indicator: &Boolean,
|
||||
statement: ConditionalStatement,
|
||||
return_type: Option<Type>,
|
||||
declared_circuit_reference: &str,
|
||||
mut_self: bool,
|
||||
span: &Span,
|
||||
) -> StatementResult<Vec<IndicatorAndConstrainedValue<F, G>>> {
|
||||
@ -96,6 +97,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
&branch_1_indicator,
|
||||
statement.block,
|
||||
return_type.clone(),
|
||||
declared_circuit_reference,
|
||||
mut_self,
|
||||
)?;
|
||||
|
||||
@ -125,6 +127,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
&branch_2_indicator,
|
||||
*nested,
|
||||
return_type,
|
||||
declared_circuit_reference,
|
||||
mut_self,
|
||||
span,
|
||||
)?,
|
||||
@ -135,6 +138,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
&branch_2_indicator,
|
||||
block,
|
||||
return_type,
|
||||
declared_circuit_reference,
|
||||
mut_self,
|
||||
)?,
|
||||
},
|
||||
|
@ -48,6 +48,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
stop: Expression,
|
||||
block: Block,
|
||||
return_type: Option<Type>,
|
||||
declared_circuit_reference: &str,
|
||||
mut_self: bool,
|
||||
span: &Span,
|
||||
) -> StatementResult<Vec<IndicatorAndConstrainedValue<F, G>>> {
|
||||
@ -75,6 +76,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
indicator,
|
||||
block.clone(),
|
||||
return_type.clone(),
|
||||
declared_circuit_reference,
|
||||
mut_self,
|
||||
)?;
|
||||
|
||||
|
@ -90,6 +90,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
indicator,
|
||||
statement,
|
||||
return_type,
|
||||
declared_circuit_reference,
|
||||
mut_self,
|
||||
&span,
|
||||
)?;
|
||||
@ -107,6 +108,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
start_stop.1,
|
||||
block,
|
||||
return_type,
|
||||
declared_circuit_reference,
|
||||
mut_self,
|
||||
&span,
|
||||
)?;
|
||||
|
@ -150,6 +150,14 @@ fn test_mutate_self_variable() {
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_variable_conditional() {
|
||||
let program_string = include_str!("mut_self_variable_conditional.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_variable_fail() {
|
||||
let program_string = include_str!("mut_self_variable_fail.leo");
|
||||
|
15
compiler/tests/circuits/mut_self_variable_conditional.leo
Normal file
15
compiler/tests/circuits/mut_self_variable_conditional.leo
Normal file
@ -0,0 +1,15 @@
|
||||
function main() {
|
||||
let mut f = Foo { a: 0u32 };
|
||||
|
||||
f.bar();
|
||||
}
|
||||
|
||||
circuit Foo {
|
||||
a: u32
|
||||
|
||||
function bar(mut self) {
|
||||
if true {
|
||||
self.a = 5u32; // Mutating a variable inside a conditional statement should work.
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user