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

@ -557,24 +557,23 @@ impl Args {
Ok(())
}
pub(crate) fn make_user_val_from_point(&self, p: [TyF64; 2]) -> Result<KclValue, KclError> {
pub(crate) fn make_kcl_val_from_point(&self, p: [f64; 2], ty: NumericType) -> Result<KclValue, KclError> {
let meta = Metadata {
source_range: self.source_range,
};
let x = KclValue::Number {
value: p[0].n,
value: p[0],
meta: vec![meta],
ty: p[0].ty.clone(),
ty: ty.clone(),
};
let y = KclValue::Number {
value: p[1].n,
value: p[1],
meta: vec![meta],
ty: p[1].ty.clone(),
ty: ty.clone(),
};
Ok(KclValue::MixedArray {
value: vec![x, y],
meta: vec![meta],
})
let ty = RuntimeType::Primitive(PrimitiveType::Number(ty));
Ok(KclValue::HomArray { value: vec![x, y], ty })
}
pub(super) fn make_user_val_from_f64_with_type(&self, f: TyF64) -> KclValue {
@ -796,7 +795,7 @@ impl<'a> FromKclValue<'a> for Vec<TagIdentifier> {
let tags = value.iter().map(|v| v.get_tag_identifier().unwrap()).collect();
Some(tags)
}
KclValue::MixedArray { value, .. } => {
KclValue::Tuple { value, .. } => {
let tags = value.iter().map(|v| v.get_tag_identifier().unwrap()).collect();
Some(tags)
}
@ -1136,8 +1135,11 @@ impl_from_kcl_for_vec!(TyF64);
impl<'a> FromKclValue<'a> for SourceRange {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
let KclValue::MixedArray { value, meta: _ } = arg else {
return None;
let value = match arg {
KclValue::Tuple { value, .. } | KclValue::HomArray { value, .. } => value,
_ => {
return None;
}
};
if value.len() != 3 {
return None;
@ -1334,7 +1336,7 @@ impl<'a> FromKclValue<'a> for TyF64 {
impl<'a> FromKclValue<'a> for [TyF64; 2] {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
match arg {
KclValue::MixedArray { value, meta: _ } | KclValue::HomArray { value, .. } => {
KclValue::Tuple { value, meta: _ } | KclValue::HomArray { value, .. } => {
if value.len() != 2 {
return None;
}
@ -1351,7 +1353,7 @@ impl<'a> FromKclValue<'a> for [TyF64; 2] {
impl<'a> FromKclValue<'a> for [TyF64; 3] {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
match arg {
KclValue::MixedArray { value, meta: _ } | KclValue::HomArray { value, .. } => {
KclValue::Tuple { value, meta: _ } | KclValue::HomArray { value, .. } => {
if value.len() != 3 {
return None;
}