1
0

Add test; Pass test by fixing type validation bug

This commit is contained in:
Jeff 2024-02-14 18:46:05 -05:00
parent 85419c47be
commit a23688803c
3 changed files with 17 additions and 16 deletions

View File

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

View File

@ -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)
}
}
}
}

View File

@ -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)))
}))
)
}