Skip to content

Commit

Permalink
Merge #674
Browse files Browse the repository at this point in the history
674: implicit value at start of array failing fix r=collinc97 a=gluax

Resolves #607.

Co-authored-by: gluax <jonathan.t.pavlik@gmail.com>
  • Loading branch information
bors[bot] and gluax committed Mar 1, 2021
2 parents 77a0af1 + c7bcab3 commit 4253ac9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions asg/src/expression/array_inline.rs
Expand Up @@ -114,7 +114,28 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<'
}
};

// If we still don't know the type iterate through processing to get a type.
// Once we encouter the type break the loop so we process as little as possible.
if expected_item.is_none() {
for expr in value.elements.iter() {
expected_item = match expr {
SpreadOrExpression::Expression(e) => {
match <&Expression<'a>>::from_ast(scope, e, expected_item.clone()) {
Ok(expr) => expr.get_type().map(Type::partial),
Err(_) => continue,
}
}
_ => None,
};

if expected_item.is_some() {
break;
}
}
}

let mut len = 0;

let output = ArrayInlineExpression {
parent: Cell::new(None),
span: Some(value.span.clone()),
Expand Down
6 changes: 6 additions & 0 deletions asg/tests/pass/array/implicit.leo
@@ -0,0 +1,6 @@
function main(){
let a = [1u8, 2u8, 3u8, 4];
let b = [1u8, 2u8, 3, 4u8];
let c = [1u8, 2, 3u8, 4u8];
let d = [1, 2u8, 3u8, 4u8];
}
6 changes: 6 additions & 0 deletions asg/tests/pass/array/mod.rs
Expand Up @@ -104,6 +104,12 @@ fn test_slice_lower() {
load_asg(program_string).unwrap();
}

#[test]
fn test_implicit() {
let program_string = include_str!("implicit.leo");
load_asg(program_string).unwrap();
}

#[test]
fn test_type_nested_value_nested_3x2() {
let program_string = include_str!("type_nested_value_nested_3x2.leo");
Expand Down

0 comments on commit 4253ac9

Please sign in to comment.