more test coverage

This commit is contained in:
gluax 2021-04-19 13:53:49 -04:00
parent f7ec5de7c9
commit 8c497f0b7a
4 changed files with 17 additions and 12 deletions

View File

@ -35,15 +35,9 @@ impl CombinerError {
Self::new_from_span(message, span) Self::new_from_span(message, span)
} }
pub fn illegal_compound_array_access(span: &Span) -> Self { pub fn illegal_compound_array_range(span: &Span) -> Self {
let message = "Illegal compound assignement with array range".to_string(); let message = "Illegal compound assignement with array range".to_string();
Self::new_from_span(message, span) Self::new_from_span(message, span)
} }
pub fn illegal_compound_operation(span: &Span) -> Self {
let message = "Illegal compound assignment operator =".to_string();
Self::new_from_span(message, span)
}
} }

View File

@ -69,7 +69,7 @@ impl Canonicalizer {
span: span.clone(), span: span.clone(),
})); }));
} }
_ => return Err(ReducerError::from(CombinerError::illegal_compound_array_access(&span))), _ => return Err(ReducerError::from(CombinerError::illegal_compound_array_range(&span))),
} }
} }
@ -79,10 +79,9 @@ impl Canonicalizer {
pub fn compound_operation_converstion( pub fn compound_operation_converstion(
&mut self, &mut self,
operation: &AssignOperation, operation: &AssignOperation,
span: &Span,
) -> Result<BinaryOperation, ReducerError> { ) -> Result<BinaryOperation, ReducerError> {
match operation { match operation {
AssignOperation::Assign => Err(ReducerError::from(CombinerError::illegal_compound_operation(&span))), AssignOperation::Assign => unreachable!(),
AssignOperation::Add => Ok(BinaryOperation::Add), AssignOperation::Add => Ok(BinaryOperation::Add),
AssignOperation::Sub => Ok(BinaryOperation::Sub), AssignOperation::Sub => Ok(BinaryOperation::Sub),
AssignOperation::Mul => Ok(BinaryOperation::Mul), AssignOperation::Mul => Ok(BinaryOperation::Mul),
@ -550,7 +549,7 @@ impl ReconstructingReducer for Canonicalizer {
&assign.span, &assign.span,
)?; )?;
let right = Box::new(Expression::Binary(binary_expr)); let right = Box::new(Expression::Binary(binary_expr));
let op = self.compound_operation_converstion(&assign.operation, &assign.span)?; let op = self.compound_operation_converstion(&assign.operation)?;
let new_value = Expression::Binary(BinaryExpression { let new_value = Expression::Binary(BinaryExpression {
left, left,
@ -573,7 +572,7 @@ impl ReconstructingReducer for Canonicalizer {
&assign.span, &assign.span,
)?; )?;
let right = Box::new(Expression::Value(value_expr)); let right = Box::new(Expression::Value(value_expr));
let op = self.compound_operation_converstion(&assign.operation, &assign.span)?; let op = self.compound_operation_converstion(&assign.operation)?;
let new_value = Expression::Binary(BinaryExpression { let new_value = Expression::Binary(BinaryExpression {
left, left,

View File

@ -0,0 +1,4 @@
function main () {
let x = [1u32; 5];
x[..2] += 1;
}

View File

@ -87,3 +87,11 @@ fn test_compound_assignment() {
assert_eq!(expected_ast, ast); assert_eq!(expected_ast, ast);
} }
#[test]
fn test_illegal_array_range_fail() {
// Check program is invalid.
let program_string = include_str!("illegal_array_range_fail.leo");
let program = parse_program(program_string);
assert!(program.is_err());
}