Add consty checks. Closes #749.

This commit is contained in:
Collin Chin 2021-03-12 19:14:31 -08:00
parent 1fbd337fec
commit 0aa71ed3f9

View File

@ -57,6 +57,19 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> {
let expected_index_type = Some(PartialType::Integer(None, Some(IntegerType::U32)));
let start = <&Expression<'a>>::from_ast(scope, &statement.start, expected_index_type.clone())?;
let stop = <&Expression<'a>>::from_ast(scope, &statement.stop, expected_index_type)?;
// Return an error if start or stop is not constant.
if !start.is_consty() {
return Err(AsgConvertError::unexpected_nonconst(
&start.span().cloned().unwrap_or_default(),
));
}
if !stop.is_consty() {
return Err(AsgConvertError::unexpected_nonconst(
&stop.span().cloned().unwrap_or_default(),
));
}
let variable = scope.alloc_variable(RefCell::new(InnerVariable {
id: scope.context.get_id(),
name: statement.variable.clone(),