Add IndexElementFn for series type probing

Introduce `IndexElementFn` as a type alias for a function that maps a
`StaticType` to an optional `StaticType` representing its element type.
This allows the `TypeChecker` to determine the element type of indexable
types like `Series` without needing to be aware of their specific
implementations.

The `series_element_type` function is created and registered with the
`TypeChecker` to handle `Series` types. This design centralizes
type-specific logic for indexable types, making the `TypeChecker` more
generic and extensible for future indexable types such as `Stream`.
This commit is contained in:
2026-03-29 13:20:49 +02:00
parent 9c434fb49d
commit 93a85cd15c
4 changed files with 44 additions and 22 deletions
+15
View File
@@ -15,6 +15,21 @@ use crate::ast::types::{NativeFunction, NodeIdentity, Purity, Signature, SourceL
// 4. Type-Inference Hooks (registered via RTL bootstrap, no name coupling)
// ============================================================================
/// Index-element hook for the `Series` type.
///
/// Returns the element type of a `Series(inner)`, or `None` for all other types.
/// Registered with `TypeChecker` so that the core type-checker remains agnostic
/// about which concrete types support integer-index access.
///
/// When `Stream` (or future indexable types) is added, extend this function
/// with additional match arms rather than touching the type-checker.
pub(crate) fn series_element_type(ty: &StaticType) -> Option<StaticType> {
match ty {
StaticType::Series(inner) => Some(*inner.clone()),
_ => None,
}
}
/// Post-call hook for `(series n)`.
/// Replaces the `Series(Any)` return type with a fresh TypeVar so that
/// subsequent `push` calls can unify the element type (HM inference).