add error and clean up

This commit is contained in:
collin 2020-09-07 22:04:23 -07:00
parent 5e4877e778
commit e916a53ed9
2 changed files with 20 additions and 13 deletions

View File

@ -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);

View File

@ -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 {