From b0de29e275936b232bcd40569cc81c0b6d149c9f Mon Sep 17 00:00:00 2001 From: Protryon Date: Thu, 11 Feb 2021 11:59:14 -0800 Subject: [PATCH] fix circuit resolution --- asg/src/scope.rs | 16 ++++++---------- asg/tests/pass/circuits/mod.rs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/asg/src/scope.rs b/asg/src/scope.rs index 52e43f5bed..8c8d29e0ca 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -218,21 +218,17 @@ impl InnerScope { .collect::, AsgConvertError>>()?, ), Circuit(name) if name.name == "Self" => Type::Circuit( - self.circuit_self - .clone() + self.resolve_circuit_self() .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, ), - Circuit(name) => Type::Circuit( - self.circuits - .get(&name.name) - .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))? - .clone(), - ), SelfType => Type::Circuit( - self.circuit_self - .clone() + self.resolve_circuit_self() .ok_or_else(AsgConvertError::reference_self_outside_circuit)?, ), + Circuit(name) => Type::Circuit( + self.resolve_circuit(&name.name) + .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, + ), }) } } diff --git a/asg/tests/pass/circuits/mod.rs b/asg/tests/pass/circuits/mod.rs index 2f0c433e9f..811eedd2d4 100644 --- a/asg/tests/pass/circuits/mod.rs +++ b/asg/tests/pass/circuits/mod.rs @@ -120,3 +120,16 @@ fn test_define_circuit_inside_circuit_function() { let program_string = include_str!("define_circuit_inside_circuit_function.leo"); load_asg(program_string).unwrap(); } + +#[test] +fn test_circuit_explicit_define() { + let program_string = r#" + circuit One { + x: u8, + } + function main () { + let x: One = One {x: 5}; + } + "#; + load_asg(program_string).unwrap(); +}