Add Optional type for filter pipes
Introduces `StaticType::Optional` to represent values that can be either of a specific type `T` or `Void`. This is crucial for handling situations in filter pipes where an expression might not always produce a value. The type checker now correctly deduces and propagates this `Optional` type, and the pipeline operator (`pipe`) is updated to unwrap `Optional(T)` results, yielding `T`. This ensures that the type system accurately reflects the potential absence of values in intermediate pipeline steps. Also includes a minor rename in the tuple-struct example from `pipe` to `p` for clarity, and registers the `streams` module.
This commit is contained in:
+7
-1
@@ -295,6 +295,7 @@ pub enum StaticType {
|
||||
DateTime,
|
||||
Text,
|
||||
Keyword,
|
||||
Optional(Box<StaticType>), // Represents T | Void (e.g. for filter pipes)
|
||||
List(Box<StaticType>), // Legacy / Dynamic list
|
||||
Series(Box<StaticType>), // Time series of a specific type
|
||||
Tuple(Vec<StaticType>), // Heterogeneous fixed-size
|
||||
@@ -318,7 +319,8 @@ impl fmt::Display for StaticType {
|
||||
StaticType::DateTime => write!(f, "datetime"),
|
||||
StaticType::Text => write!(f, "text"),
|
||||
StaticType::Keyword => write!(f, "keyword"),
|
||||
StaticType::List(inner) => write!(f, "[{}]", inner),
|
||||
StaticType::Optional(inner) => write!(f, "optional({})", inner),
|
||||
StaticType::List(inner) => write!(f, "list({})", inner),
|
||||
StaticType::Series(inner) => write!(f, "series<{}>", inner),
|
||||
StaticType::Tuple(elements) => {
|
||||
write!(f, "[")?;
|
||||
@@ -371,6 +373,10 @@ impl StaticType {
|
||||
}
|
||||
|
||||
match (self, other) {
|
||||
// Optional(T) is assignable from T or Void
|
||||
(StaticType::Optional(inner), other) => {
|
||||
matches!(other, StaticType::Void) || inner.is_assignable_from(other)
|
||||
}
|
||||
// A Vector is a Tuple
|
||||
(StaticType::Tuple(elements), StaticType::Vector(inner, len)) => {
|
||||
if elements.len() != *len {
|
||||
|
||||
Reference in New Issue
Block a user