mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 03:04:13 +03:00
add error and clean up
This commit is contained in:
parent
5e4877e778
commit
e916a53ed9
@ -140,6 +140,12 @@ impl ExpressionError {
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn self_keyword(span: Span) -> Self {
|
||||
let message = format!("cannot call keyword `Self` outside of a circuit function");
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn undefined_array(actual: String, span: Span) -> Self {
|
||||
let message = format!("array `{}` must be declared before it is used in an expression", actual);
|
||||
|
||||
|
@ -38,25 +38,26 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
// Get defined circuit
|
||||
let circuit = match *circuit_identifier.clone() {
|
||||
Expression::Identifier(identifier) => {
|
||||
// Use the "Self" keyword to access a static circuit function
|
||||
if identifier.is_self() {
|
||||
let circuit = self.get(&file_scope).unwrap();
|
||||
let circuit = self
|
||||
.get(&file_scope)
|
||||
.ok_or(ExpressionError::self_keyword(identifier.span.clone()))?;
|
||||
|
||||
circuit.to_owned().extract_circuit(span.clone())?
|
||||
circuit.to_owned()
|
||||
} else {
|
||||
self.evaluate_identifier(file_scope.clone(), function_scope.clone(), expected_type, identifier)?
|
||||
.extract_circuit(span.clone())?
|
||||
}
|
||||
}
|
||||
expression => self
|
||||
.enforce_expression(
|
||||
cs,
|
||||
file_scope.clone(),
|
||||
function_scope.clone(),
|
||||
expected_type,
|
||||
expression,
|
||||
)?
|
||||
.extract_circuit(span.clone())?,
|
||||
};
|
||||
expression => self.enforce_expression(
|
||||
cs,
|
||||
file_scope.clone(),
|
||||
function_scope.clone(),
|
||||
expected_type,
|
||||
expression,
|
||||
)?,
|
||||
}
|
||||
.extract_circuit(span.clone())?;
|
||||
|
||||
// Find static circuit function
|
||||
let matched_function = circuit.members.into_iter().find(|member| match member {
|
||||
|
Loading…
Reference in New Issue
Block a user