Remove KclValue::Int (#5369)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-02-14 08:28:00 +13:00
committed by GitHub
parent a572d7b0db
commit 49d52ce94b
10 changed files with 81 additions and 577 deletions

View File

@ -123243,32 +123243,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -125487,32 +125461,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -127735,32 +127683,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -194469,32 +194391,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -196712,32 +196608,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -197269,32 +197139,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -204262,32 +204106,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -206503,32 +206321,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -207032,32 +206824,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -209274,32 +209040,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -209831,32 +209571,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -212063,32 +211777,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -214304,32 +213992,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -214833,32 +214495,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -217077,32 +216713,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -219319,32 +218929,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [
@ -219876,32 +219460,6 @@
}
}
},
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Int"
]
},
"value": {
"type": "integer",
"format": "int64"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{
"type": "object",
"required": [

View File

@ -70,23 +70,6 @@ Any KCL value.
## Properties
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `type` |enum: `Int`| | No |
| `value` |`integer`| | No |
| `__meta` |`[` [`Metadata`](/docs/kcl/types/Metadata) `]`| | No |
----
**Type:** `object`
## Properties
| Property | Type | Description | Required |

View File

@ -792,15 +792,6 @@ impl Node<UnaryExpression> {
}];
Ok(KclValue::Number { value: -value, meta })
}
KclValue::Int { value, meta: _ } => {
let meta = vec![Metadata {
source_range: self.into(),
}];
Ok(KclValue::Number {
value: (-value) as f64,
meta,
})
}
_ => Err(KclError::Semantic(KclErrorDetails {
message: format!(
"You can only negate numbers, but this is a {}",
@ -1299,8 +1290,8 @@ impl Node<ArrayRangeExpression> {
Ok(KclValue::Array {
value: range
.into_iter()
.map(|num| KclValue::Int {
value: num,
.map(|num| KclValue::Number {
value: num as f64,
meta: meta.clone(),
})
.collect(),
@ -1342,8 +1333,6 @@ fn article_for(s: &str) -> &'static str {
pub fn parse_number_as_f64(v: &KclValue, source_range: SourceRange) -> Result<f64, KclError> {
if let KclValue::Number { value: n, .. } = &v {
Ok(*n)
} else if let KclValue::Int { value: n, .. } = &v {
Ok(*n as f64)
} else {
let actual_type = v.human_friendly_type();
let article = if actual_type.starts_with(['a', 'e', 'i', 'o', 'u']) {
@ -1460,15 +1449,6 @@ fn jvalue_to_prop(value: &KclValue, property_sr: Vec<SourceRange>, name: &str) -
}))
};
match value {
KclValue::Int { value:num, meta: _ } => {
let maybe_int: Result<usize, _> = (*num).try_into();
if let Ok(uint) = maybe_int {
Ok(Property::UInt(uint))
}
else {
make_err(format!("'{num}' is negative, so you can't index an array with it"))
}
}
KclValue::Number{value: num, meta:_} => {
let num = *num;
if num < 0.0 {
@ -1731,8 +1711,8 @@ mod test {
fn test_assign_args_to_params() {
// Set up a little framework for this test.
fn mem(number: usize) -> KclValue {
KclValue::Int {
value: number as i64,
KclValue::Number {
value: number as f64,
meta: Default::default(),
}
}

View File

@ -43,11 +43,6 @@ pub enum KclValue {
#[serde(rename = "__meta")]
meta: Vec<Metadata>,
},
Int {
value: i64,
#[serde(rename = "__meta")]
meta: Vec<Metadata>,
},
String {
value: String,
#[serde(rename = "__meta")]
@ -168,7 +163,6 @@ impl From<KclValue> for Vec<SourceRange> {
KclValue::Face { value } => to_vec_sr(&value.meta),
KclValue::Bool { meta, .. } => to_vec_sr(&meta),
KclValue::Number { meta, .. } => to_vec_sr(&meta),
KclValue::Int { meta, .. } => to_vec_sr(&meta),
KclValue::String { meta, .. } => to_vec_sr(&meta),
KclValue::Array { meta, .. } => to_vec_sr(&meta),
KclValue::Object { meta, .. } => to_vec_sr(&meta),
@ -200,7 +194,6 @@ impl From<&KclValue> for Vec<SourceRange> {
KclValue::Face { value } => to_vec_sr(&value.meta),
KclValue::Bool { meta, .. } => to_vec_sr(meta),
KclValue::Number { meta, .. } => to_vec_sr(meta),
KclValue::Int { meta, .. } => to_vec_sr(meta),
KclValue::String { meta, .. } => to_vec_sr(meta),
KclValue::Uuid { meta, .. } => to_vec_sr(meta),
KclValue::Array { meta, .. } => to_vec_sr(meta),
@ -218,7 +211,6 @@ impl KclValue {
KclValue::Uuid { value: _, meta } => meta.clone(),
KclValue::Bool { value: _, meta } => meta.clone(),
KclValue::Number { value: _, meta } => meta.clone(),
KclValue::Int { value: _, meta } => meta.clone(),
KclValue::String { value: _, meta } => meta.clone(),
KclValue::Array { value: _, meta } => meta.clone(),
KclValue::Object { value: _, meta } => meta.clone(),
@ -297,7 +289,6 @@ impl KclValue {
KclValue::Face { .. } => "Face",
KclValue::Bool { .. } => "boolean (true/false value)",
KclValue::Number { .. } => "number",
KclValue::Int { .. } => "integer",
KclValue::String { .. } => "string (text)",
KclValue::Array { .. } => "array (list)",
KclValue::Object { .. } => "object",
@ -349,7 +340,6 @@ impl KclValue {
pub(crate) fn as_usize(&self) -> Option<usize> {
match self {
KclValue::Int { value, .. } if *value > 0 => Some(*value as usize),
KclValue::Number { value, .. } => crate::try_f64_to_usize(*value),
_ => None,
}
@ -357,7 +347,6 @@ impl KclValue {
pub fn as_int(&self) -> Option<i64> {
match self {
KclValue::Int { value, .. } => Some(*value),
KclValue::Number { value, .. } => crate::try_f64_to_i64(*value),
_ => None,
}
@ -440,8 +429,6 @@ impl KclValue {
pub fn as_f64(&self) -> Option<f64> {
if let KclValue::Number { value, meta: _ } = &self {
Some(*value)
} else if let KclValue::Int { value, meta: _ } = &self {
Some(*value as f64)
} else {
None
}

View File

@ -852,8 +852,8 @@ mod test {
}
fn val(value: i64) -> KclValue {
KclValue::Int {
value,
KclValue::Number {
value: value as f64,
meta: Vec::new(),
}
}
@ -861,14 +861,14 @@ mod test {
#[track_caller]
fn assert_get(mem: &ProgramMemory, key: &str, n: i64) {
match mem.get(key, sr()).unwrap() {
KclValue::Int { value, .. } => assert_eq!(*value, n),
KclValue::Number { value, .. } => assert_eq!(*value as i64, n),
_ => unreachable!(),
}
}
fn expect_int(value: &KclValue) -> Option<i64> {
fn expect_small_number(value: &KclValue) -> Option<i64> {
match value {
KclValue::Int { value, .. } => Some(*value),
KclValue::Number { value, .. } if value > &0.0 && value < &10.0 => Some(*value as i64),
_ => None,
}
}
@ -876,7 +876,7 @@ mod test {
#[track_caller]
fn assert_get_from(mem: &ProgramMemory, key: &str, n: i64, snapshot: EnvironmentRef) {
match mem.get_from(key, snapshot, sr()).unwrap() {
KclValue::Int { value, .. } => assert_eq!(*value, n),
KclValue::Number { value, .. } => assert_eq!(*value as i64, n),
_ => unreachable!(),
}
}
@ -1127,7 +1127,7 @@ mod test {
assert_get_from(mem, "b", 3, sn3);
assert_get_from(mem, "b", 4, sn4);
let vals: Vec<_> = mem.walk_call_stack().filter_map(expect_int).collect();
let vals: Vec<_> = mem.walk_call_stack().filter_map(expect_small_number).collect();
let expected = [6, 1, 3, 1, 7];
assert_eq!(vals, expected);
@ -1136,7 +1136,7 @@ mod test {
mem.get_from("b", sn1, sr()).unwrap_err();
assert_get_from(mem, "b", 3, sn2);
let vals: Vec<_> = mem.walk_call_stack().filter_map(expect_int).collect();
let vals: Vec<_> = mem.walk_call_stack().filter_map(expect_small_number).collect();
let expected = [1, 7];
assert_eq!(vals, expected);

View File

@ -1391,7 +1391,6 @@ impl<'a> FromKclValue<'a> for i64 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
match arg {
KclValue::Number { value, meta: _ } => crate::try_f64_to_i64(*value),
KclValue::Int { value, meta: _ } => Some(*value),
_ => None,
}
}
@ -1428,7 +1427,6 @@ impl<'a> FromKclValue<'a> for u32 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
match arg {
KclValue::Number { value, meta: _ } => crate::try_f64_to_u32(*value),
KclValue::Int { value, meta: _ } => Some(*value as u32),
_ => None,
}
}
@ -1444,7 +1442,6 @@ impl<'a> FromKclValue<'a> for u64 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
match arg {
KclValue::Number { value, meta: _ } => crate::try_f64_to_u64(*value),
KclValue::Int { value, meta: _ } => Some(*value as u64),
_ => None,
}
}
@ -1453,7 +1450,6 @@ impl<'a> FromKclValue<'a> for f64 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
match arg {
KclValue::Number { value, meta: _ } => Some(*value),
KclValue::Int { value, meta: _ } => Some(*value as f64),
_ => None,
}
}

View File

@ -446,7 +446,7 @@ async fn make_transform<T: GeometryTrait>(
exec_state: &mut ExecState,
) -> Result<Vec<Transform>, KclError> {
// Call the transform fn for this repetition.
let repetition_num = KclValue::Int {
let repetition_num = KclValue::Number {
value: i.into(),
meta: vec![source_range.into()],
};

View File

@ -53,8 +53,8 @@ description: Variables in memory after executing array_range_expr.kcl
"type": "Array",
"value": [
{
"type": "Int",
"value": 0,
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
@ -66,8 +66,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -79,8 +79,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -92,8 +92,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -105,8 +105,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [
@ -132,8 +132,8 @@ description: Variables in memory after executing array_range_expr.kcl
"type": "Array",
"value": [
{
"type": "Int",
"value": 0,
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
@ -145,8 +145,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -158,8 +158,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -171,8 +171,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -184,8 +184,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [
@ -211,8 +211,8 @@ description: Variables in memory after executing array_range_expr.kcl
"type": "Array",
"value": [
{
"type": "Int",
"value": 0,
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
@ -224,8 +224,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -237,8 +237,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -250,8 +250,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -263,8 +263,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [
@ -276,8 +276,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 5,
"type": "Number",
"value": 5.0,
"__meta": [
{
"sourceRange": [
@ -303,8 +303,8 @@ description: Variables in memory after executing array_range_expr.kcl
"type": "Array",
"value": [
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -316,8 +316,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -329,8 +329,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -342,8 +342,8 @@ description: Variables in memory after executing array_range_expr.kcl
]
},
{
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [

View File

@ -27,8 +27,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
"type": "Array",
"value": [
{
"type": "Int",
"value": -5,
"type": "Number",
"value": -5.0,
"__meta": [
{
"sourceRange": [
@ -40,8 +40,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": -4,
"type": "Number",
"value": -4.0,
"__meta": [
{
"sourceRange": [
@ -53,8 +53,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": -3,
"type": "Number",
"value": -3.0,
"__meta": [
{
"sourceRange": [
@ -66,8 +66,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": -2,
"type": "Number",
"value": -2.0,
"__meta": [
{
"sourceRange": [
@ -79,8 +79,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": -1,
"type": "Number",
"value": -1.0,
"__meta": [
{
"sourceRange": [
@ -92,8 +92,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": 0,
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
@ -105,8 +105,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -118,8 +118,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -131,8 +131,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -144,8 +144,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [
@ -157,8 +157,8 @@ description: Variables in memory after executing array_range_negative_expr.kcl
]
},
{
"type": "Int",
"value": 5,
"type": "Number",
"value": 5.0,
"__meta": [
{
"sourceRange": [

View File

@ -96,8 +96,8 @@ description: Variables in memory after executing double_map_fn.kcl
"type": "Array",
"value": [
{
"type": "Int",
"value": 0,
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
@ -109,8 +109,8 @@ description: Variables in memory after executing double_map_fn.kcl
]
},
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -122,8 +122,8 @@ description: Variables in memory after executing double_map_fn.kcl
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [