diff --git a/src/abstract_tree/as.rs b/src/abstract_tree/as.rs index 210bc37..3e87b9d 100644 --- a/src/abstract_tree/as.rs +++ b/src/abstract_tree/as.rs @@ -57,25 +57,18 @@ impl AbstractTree for As { }); } } + Type::Any => { // Do no validation when converting from "any" to a list. // This effectively defers to runtime behavior, potentially // causing a runtime error. } - Type::Boolean => todo!(), - Type::Collection => todo!(), - Type::Custom(_) => todo!(), - Type::Float => todo!(), - Type::Function { - parameter_types: _, - return_type: _, - } => todo!(), - Type::Integer => todo!(), - Type::Map(_) => todo!(), - Type::None => todo!(), - Type::Number => todo!(), - Type::Range => todo!(), - Type::Option(_) => todo!(), + _ => { + return Err(ValidationError::ConversionImpossible { + initial_type, + target_type: self.r#type.clone(), + }) + } } } diff --git a/src/abstract_tree/function_call.rs b/src/abstract_tree/function_call.rs index 621ff2e..6d9d189 100644 --- a/src/abstract_tree/function_call.rs +++ b/src/abstract_tree/function_call.rs @@ -87,7 +87,15 @@ impl AbstractTree for FunctionCall { Ok(value_type) } } - FunctionExpression::Index(index) => index.expected_type(context), + FunctionExpression::Index(index) => { + let index_type = index.expected_type(context)?; + + if let Type::Function { return_type, .. } = index_type { + Ok(*return_type) + } else { + Ok(index_type) + } + } } } diff --git a/tests/as.rs b/tests/as.rs index 61add06..1be8996 100644 --- a/tests/as.rs +++ b/tests/as.rs @@ -39,7 +39,7 @@ fn conversion_runtime_error() { interpret(&format!("json:parse('{JSON}') as [map]")), Err(Error::Runtime(RuntimeError::ConversionImpossible { value: json_value, - target_type: Type::List(Box::new(Type::Float)) + target_type: Type::List(Box::new(Type::Map(None))) })) ) }