Skip to content

Fix the KCL any type to not panic #6748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Fix the KCL any type to not panic #6748

wants to merge 12 commits into from

Conversation

jtran
Copy link
Contributor

@jtran jtran commented May 7, 2025

I was trying to understand and test the limits of HomArray and MixedArray. I tried to make functions that use any as a type, and this needed fixing.

With this PR, the following KCL works.

fn id(@x: any): any {
  return x
}

fn singleton(@x: any): [any; 1] {
  return [x]
}

fn len(@a: [any]): number(_) {
  return reduce(a, initial = 0, f = fn(_, count) {
    return count + 1
  })
}

@jtran jtran requested a review from nrc May 7, 2025 20:04
Copy link

qa-wolf bot commented May 7, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented May 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2025 10:28pm

@jtran jtran force-pushed the jtran/test-arrays branch from ed2bda1 to e959645 Compare May 7, 2025 20:07
Copy link

codspeed-hq bot commented May 7, 2025

CodSpeed Instrumentation Performance Report

Merging #6748 will not alter performance

Comparing jtran/test-arrays (383afbf) with main (fc3ce4c)

Summary

✅ 54 untouched benchmarks

Copy link
Contributor

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect all those tests to pass, if they don't then I suspect that the any type hasn't been properly wired up in execution and just exists as syntax for documentation

@jtran jtran changed the title test: Add tests for types and arrays Fix the KCL any type to not panic May 8, 2025
@jtran jtran marked this pull request as ready for review May 8, 2025 00:52
@jtran jtran requested a review from nrc May 8, 2025 00:53
@@ -1020,6 +1024,7 @@ impl KclValue {
_ => self,
};
match ty {
PrimitiveType::Any => Ok(value.clone()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think subtype should be altered so that any is a supertype of everything, and then this line is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating subtype made my tests fail in a weird way 😖 so this still needs some work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of implicit coercion of single values into arrays, we were coercing an empty MixedArray into HomArray { value: vec![MixedArray { ... }] }. Fix is here: 3a07212.

@jtran jtran force-pushed the jtran/test-arrays branch from f24e776 to a1ed0ae Compare May 8, 2025 02:25
@jtran jtran enabled auto-merge (squash) May 8, 2025 02:46
@jtran jtran disabled auto-merge May 8, 2025 03:01
@jtran jtran marked this pull request as draft May 8, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants