Fix the KCL any type and array coercion incorrectly nesting (#6816)

* Add sim test for any type

* Fix doc comments to match code

* Add array ascription tests

* Commit new test output

* Fix to not panic when type is undefined

* Fix to not panic on use of the any type

* Update test and generated output

* Fix error message after rebase

* Fix subtype of any

* Fix KCL to use new keyword args

* Fix to not nest MixedArray in HomArray

* Update output

* Remove all creation of MixedArray and use HomArray instead

* Rename MixedArray to Tuple

* Fix to coerce arrays the way tuples are done

* Restructure to appease the type signature extraction

* Fix TS unit test

* Update output after switch to HomArray

* Update docs

* Fix to remove edge case when creating points

* Update docs with broken point signature

* Fix display of tuples to not collide with arrays

* Change push to an array with type mismatch to be an error

* Add sim test for push type error

* Fix acription to more general array element type

* Fix to coerce point types

* Change array push to not error when item type differs

* Fix coercion tests

* Change to only flatten as a last resort and remove flattening tuples

* Contort code to appease doc generation

* Update docs

* Fix coerce axes

* Fix flattening test to test arrays instead of tuples

* Remove special subtype case for singleton coercion
This commit is contained in:
Jonathan Tran
2025-05-11 23:57:31 -04:00
committed by GitHub
parent 86e8bcfe0b
commit bbe89f56a7
53 changed files with 2942 additions and 1839 deletions

View File

@ -452,7 +452,7 @@ async fn make_transform<T: GeometryTrait>(
})?;
let transforms = match transform_fn_return {
KclValue::Object { value, meta: _ } => vec![value],
KclValue::MixedArray { value, meta: _ } => {
KclValue::Tuple { value, .. } | KclValue::HomArray { value, .. } => {
let transforms: Vec<_> = value
.into_iter()
.map(|val| {
@ -671,12 +671,44 @@ impl GeometryTrait for Solid {
#[cfg(test)]
mod tests {
use super::*;
use crate::execution::types::NumericType;
use crate::execution::types::{NumericType, PrimitiveType};
#[tokio::test(flavor = "multi_thread")]
async fn test_array_to_point3d() {
let mut exec_state = ExecState::new(&ExecutorContext::new_mock().await);
let input = KclValue::MixedArray {
let input = KclValue::HomArray {
value: vec![
KclValue::Number {
value: 1.1,
meta: Default::default(),
ty: NumericType::mm(),
},
KclValue::Number {
value: 2.2,
meta: Default::default(),
ty: NumericType::mm(),
},
KclValue::Number {
value: 3.3,
meta: Default::default(),
ty: NumericType::mm(),
},
],
ty: RuntimeType::Primitive(PrimitiveType::Number(NumericType::mm())),
};
let expected = [
TyF64::new(1.1, NumericType::mm()),
TyF64::new(2.2, NumericType::mm()),
TyF64::new(3.3, NumericType::mm()),
];
let actual = array_to_point3d(&input, Vec::new(), &mut exec_state);
assert_eq!(actual.unwrap(), expected);
}
#[tokio::test(flavor = "multi_thread")]
async fn test_tuple_to_point3d() {
let mut exec_state = ExecState::new(&ExecutorContext::new_mock().await);
let input = KclValue::Tuple {
value: vec![
KclValue::Number {
value: 1.1,