674: implicit value at start of array failing fix r=collinc97 a=gluax

Resolves #607.

Co-authored-by: gluax <jonathan.t.pavlik@gmail.com>
This commit is contained in:
bors[bot] 2021-03-01 23:57:43 +00:00 committed by GitHub
commit 4253ac9133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -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()),

View File

@ -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];
}

View File

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