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

@ -226,6 +226,7 @@ impl PrimitiveType {
pub fn compute_digest(&mut self) -> Digest {
let mut hasher = Sha256::new();
match self {
PrimitiveType::Any => hasher.update(b"any"),
PrimitiveType::Named(id) => hasher.update(id.compute_digest()),
PrimitiveType::String => hasher.update(b"string"),
PrimitiveType::Number(suffix) => hasher.update(suffix.digestable_id()),

View File

@ -3186,6 +3186,8 @@ impl PipeExpression {
#[ts(export)]
#[serde(tag = "p_type")]
pub enum PrimitiveType {
/// The super type of all other types.
Any,
/// A string type.
String,
/// A number type.
@ -3202,6 +3204,7 @@ pub enum PrimitiveType {
impl PrimitiveType {
pub fn primitive_from_str(s: &str, suffix: Option<NumericSuffix>) -> Option<Self> {
match (s, suffix) {
("any", None) => Some(PrimitiveType::Any),
("string", None) => Some(PrimitiveType::String),
("bool", None) => Some(PrimitiveType::Boolean),
("tag", None) => Some(PrimitiveType::Tag),
@ -3215,6 +3218,7 @@ impl PrimitiveType {
impl fmt::Display for PrimitiveType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PrimitiveType::Any => write!(f, "any"),
PrimitiveType::Number(suffix) => {
write!(f, "number")?;
if *suffix != NumericSuffix::None {