implicit value at start of array failing fix

This commit is contained in:
gluax 2021-02-17 11:27:33 -05:00
parent a7c9caf4b3
commit 317fc08fc5
4 changed files with 37 additions and 1 deletions

View File

@ -105,6 +105,7 @@ impl FromAst<leo_ast::ArrayInlineExpression> for ArrayInlineExpression {
value: &leo_ast::ArrayInlineExpression,
expected_type: Option<PartialType>,
) -> Result<ArrayInlineExpression, AsgConvertError> {
// println!("v: {:?}", value);
let (mut expected_item, expected_len) = match expected_type {
Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims),
None => (None, None),
@ -118,6 +119,27 @@ impl FromAst<leo_ast::ArrayInlineExpression> for ArrayInlineExpression {
};
let mut len = 0;
if len == 0 && expected_item.is_none() {
for expr in value.elements.iter() {
expected_item = match expr {
SpreadOrExpression::Expression(e) => {
match Arc::<Expression>::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 output = ArrayInlineExpression {
parent: RefCell::new(None),
span: Some(value.span.clone()),

View File

@ -161,7 +161,9 @@ impl FromAst<leo_ast::ValueExpression> for Constant {
}
}
Implicit(value, span) => match expected_type {
None => return Err(AsgConvertError::unresolved_type("unknown", span)),
None => {
return Err(AsgConvertError::unresolved_type("unknown", span))
},
Some(PartialType::Integer(Some(sub_type), _)) | Some(PartialType::Integer(None, Some(sub_type))) => {
Constant {
parent: RefCell::new(None),

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