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:
@@ -373,8 +373,8 @@ impl TypeChecker {
|
||||
}
|
||||
else_typed = Some(Box::new(et));
|
||||
} else {
|
||||
// If without else returns Void or Optional(Then)
|
||||
final_ty = StaticType::Any; // Delphi: MakeOptional(Then)
|
||||
// If without else returns Optional(Then) (T | Void)
|
||||
final_ty = StaticType::Optional(Box::new(then_typed.ty.clone()));
|
||||
}
|
||||
|
||||
(
|
||||
@@ -394,7 +394,12 @@ impl TypeChecker {
|
||||
}
|
||||
let typed_lambda = self.check_node(*lambda, ctx)?;
|
||||
let ret_ty = if let StaticType::Function(sig) = &typed_lambda.ty {
|
||||
sig.ret.clone()
|
||||
// If the lambda returns an Optional(T), the pipeline filters Void and stores T!
|
||||
if let StaticType::Optional(inner) = &sig.ret {
|
||||
*inner.clone()
|
||||
} else {
|
||||
sig.ret.clone()
|
||||
}
|
||||
} else {
|
||||
StaticType::Any
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user