Files
RustAst/tests/rtl_series.rs
T
Brummel d7d1aef8ed Refactor type checker for series and overloads
Introduce `unify_matched_overload` to handle type variable propagation
for overloaded functions. This ensures that when an overload is chosen,
its concrete parameter types are unified with the actual argument types.
This is crucial for resolving type variables nested within closures
called through overloaded functions.

Additionally, this commit:
- Allows `series` to infer schema type from `push` calls, simplifying
  its signature.
- Adds a fallback to `ValueSeries` in `rtl::series` if schema injection
  fails.
- Updates `StaticType::TypeVar` to return `Any` when accessed,
  simplifying field access logic.
- Adjusts tests to reflect the simplified `series` signature.
2026-03-28 14:03:48 +01:00

54 lines
1.6 KiB
Rust

use myc::ast::environment::Environment;
use myc::ast::types::Value;
#[test]
fn test_series_api_with_limit() {
let env = Environment::new();
// (series limit) — schema is inferred from push calls
let source = "(series 100)";
let result = env.compile(source).into_result();
assert!(result.is_ok(), "Series creation with limit should work: {:?}", result.err());
}
/// Regression test for HM type inference through nested closures.
///
/// `series` is created in an outer closure, `push` happens in an inner closure.
/// The pushed value type must propagate back through the TypeVar chain so that
/// the compiler can inject the `:float` schema — no explicit schema given.
#[test]
fn test_series_infer_type_from_nested_closure() {
let env = Environment::new();
let source = r#"
(do
(def make-acc
(fn [n]
(do
(def s (series n))
(def total 0.0)
(fn [x]
(do
(assign total (+ total x))
(push s x)
(s 0))))))
(def acc (make-acc 5))
(acc 1.5))
"#;
let result = env.run_script(source);
match result {
Ok(Value::Float(v)) if (v - 1.5).abs() < 1e-9 => {}
other => panic!("Expected Float(1.5), got {:?}", other),
}
}
#[test]
fn test_record_structural_equality_order() {
let env = Environment::new();
// Known design choice: currently order dependent.
let source = "(= {:a 1 :b 2} {:b 2 :a 1})";
let result = env.run_script(source);
match result {
Ok(Value::Bool(false)) => {},
_ => panic!("Expected false (current implementation behavior)"),
}
}