mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 11:12:48 +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)
|
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 {
|
pub fn undefined_array(actual: String, span: Span) -> Self {
|
||||||
let message = format!("array `{}` must be declared before it is used in an expression", actual);
|
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
|
// Get defined circuit
|
||||||
let circuit = match *circuit_identifier.clone() {
|
let circuit = match *circuit_identifier.clone() {
|
||||||
Expression::Identifier(identifier) => {
|
Expression::Identifier(identifier) => {
|
||||||
|
// Use the "Self" keyword to access a static circuit function
|
||||||
if identifier.is_self() {
|
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 {
|
} else {
|
||||||
self.evaluate_identifier(file_scope.clone(), function_scope.clone(), expected_type, identifier)?
|
self.evaluate_identifier(file_scope.clone(), function_scope.clone(), expected_type, identifier)?
|
||||||
.extract_circuit(span.clone())?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expression => self
|
expression => self.enforce_expression(
|
||||||
.enforce_expression(
|
cs,
|
||||||
cs,
|
file_scope.clone(),
|
||||||
file_scope.clone(),
|
function_scope.clone(),
|
||||||
function_scope.clone(),
|
expected_type,
|
||||||
expected_type,
|
expression,
|
||||||
expression,
|
)?,
|
||||||
)?
|
}
|
||||||
.extract_circuit(span.clone())?,
|
.extract_circuit(span.clone())?;
|
||||||
};
|
|
||||||
|
|
||||||
// Find static circuit function
|
// Find static circuit function
|
||||||
let matched_function = circuit.members.into_iter().find(|member| match member {
|
let matched_function = circuit.members.into_iter().find(|member| match member {
|
||||||
|
Loading…
Reference in New Issue
Block a user