Fix: Improve series type handling and coercions

This commit enhances the series type handling in `src/ast/rtl/series.rs`
by introducing helper methods `as_float` and `as_int` in
`src/ast/types.rs` to manage type conversions more robustly.

It also updates the function overload resolution in `src/ast/types.rs`
to prioritize exact parameter matches before falling back to implicit
coercions.

Finally, the example `err.myc` has been updated to reflect a more
accurate implementation of a Simple Moving Average (SMA) calculation.
This commit is contained in:
Michael Schimmel
2026-03-06 16:31:50 +01:00
parent 7e3b000d99
commit 7b6f6e52bd
4 changed files with 83 additions and 35 deletions
+4 -7
View File
@@ -218,19 +218,16 @@ pub trait SeriesMember: Object + Series {
impl SeriesMember for ScalarSeries<f64> {
fn push_value(&self, value: Value, limit: Option<usize>) {
match value {
Value::Float(v) => self.data.borrow_mut().push(v, limit),
Value::Int(v) => self.data.borrow_mut().push(v as f64, limit),
_ => {}
if let Some(v) = value.as_float() {
self.data.borrow_mut().push(v, limit);
}
}
}
impl SeriesMember for ScalarSeries<i64> {
fn push_value(&self, value: Value, limit: Option<usize>) {
match value {
Value::Int(v) | Value::DateTime(v) => self.data.borrow_mut().push(v, limit),
_ => {}
if let Some(v) = value.as_int() {
self.data.borrow_mut().push(v, limit);
}
}
}