Implement coercion of numeric types for ascription and arithmetic (off by default) (#6175)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-04-07 16:13:15 +12:00
committed by GitHub
parent ce7a967f5f
commit e7b23e1638
72 changed files with 2789 additions and 1604 deletions

View File

@ -15,7 +15,7 @@ use crate::{
parsing::ast::types::{
DefaultParamVal, FunctionExpression, KclNone, Literal, LiteralValue, Node, TagDeclarator, TagNode,
},
std::StdFnProps,
std::{args::TyF64, StdFnProps},
CompilationError, KclError, ModuleId, SourceRange,
};
@ -495,6 +495,7 @@ impl KclValue {
None
}
}
pub fn as_f64(&self) -> Option<f64> {
if let KclValue::Number { value, .. } = &self {
Some(*value)
@ -503,6 +504,14 @@ impl KclValue {
}
}
pub fn as_ty_f64(&self) -> Option<TyF64> {
if let KclValue::Number { value, ty, .. } = &self {
Some(TyF64::new(*value, ty.clone()))
} else {
None
}
}
pub fn as_bool(&self) -> Option<bool> {
if let KclValue::Bool { value, meta: _ } = &self {
Some(*value)