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:
@ -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)
|
||||
|
Reference in New Issue
Block a user