From 8c497f0b7ad84daf061ef299ee53741c1bd946a9 Mon Sep 17 00:00:00 2001 From: gluax Date: Mon, 19 Apr 2021 13:53:49 -0400 Subject: [PATCH] more test coverage --- ast/src/errors/combiner.rs | 8 +------- ast/src/reducer/canonicalization.rs | 9 ++++----- .../tests/canonicalization/illegal_array_range_fail.leo | 4 ++++ compiler/tests/canonicalization/mod.rs | 8 ++++++++ 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 compiler/tests/canonicalization/illegal_array_range_fail.leo diff --git a/ast/src/errors/combiner.rs b/ast/src/errors/combiner.rs index 7c8aa72375..5a1022db27 100644 --- a/ast/src/errors/combiner.rs +++ b/ast/src/errors/combiner.rs @@ -35,15 +35,9 @@ impl CombinerError { 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(); 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) - } } diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index bdba3ab7f8..7237d88d69 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -69,7 +69,7 @@ impl Canonicalizer { 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( &mut self, operation: &AssignOperation, - span: &Span, ) -> Result { match operation { - AssignOperation::Assign => Err(ReducerError::from(CombinerError::illegal_compound_operation(&span))), + AssignOperation::Assign => unreachable!(), AssignOperation::Add => Ok(BinaryOperation::Add), AssignOperation::Sub => Ok(BinaryOperation::Sub), AssignOperation::Mul => Ok(BinaryOperation::Mul), @@ -550,7 +549,7 @@ impl ReconstructingReducer for Canonicalizer { &assign.span, )?; 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 { left, @@ -573,7 +572,7 @@ impl ReconstructingReducer for Canonicalizer { &assign.span, )?; 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 { left, diff --git a/compiler/tests/canonicalization/illegal_array_range_fail.leo b/compiler/tests/canonicalization/illegal_array_range_fail.leo new file mode 100644 index 0000000000..af14957712 --- /dev/null +++ b/compiler/tests/canonicalization/illegal_array_range_fail.leo @@ -0,0 +1,4 @@ +function main () { + let x = [1u32; 5]; + x[..2] += 1; +} \ No newline at end of file diff --git a/compiler/tests/canonicalization/mod.rs b/compiler/tests/canonicalization/mod.rs index fd2db5da3f..f420b2370c 100644 --- a/compiler/tests/canonicalization/mod.rs +++ b/compiler/tests/canonicalization/mod.rs @@ -87,3 +87,11 @@ fn test_compound_assignment() { 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()); +}