dax: document the variable index and look through VAR/RETURN in operand checks (#2228)

This commit is contained in:
alosslessdev
2026-11-05 07:20:13 -05:00
parent c37fa6a799
commit f00e1da135
2 changed files with 14 additions and 2 deletions
+6 -1
View File
@@ -63,7 +63,12 @@ pub enum BoundExpr {
TableConstructor(Vec<BoundExpr>),
/// `( value, ... )`.
Tuple(Vec<BoundExpr>),
/// A variable reference, indexed in the enclosing [`BoundExpr::VarReturn`].
/// A variable reference.
///
/// `index` is the variable's absolute slot in the cumulative stack of every enclosing
/// [`BoundExpr::VarReturn`] block — outer blocks first, each block appending its own
/// declarations in order — not its position inside the innermost `vars` list. The evaluator
/// pushes each block's values onto the same stack, so the index stays valid across nesting.
Variable {
index: usize,
name: String,
+8 -1
View File
@@ -321,7 +321,14 @@ pub const fn literal_type(literal: &Literal) -> DataType {
/// evaluation time (`LASTDATE('Date'[Date]) - 1`), so it is unknown here rather than a table.
fn scalar_operand(expr: &Expr) -> Result<InferredType, TypeError> {
let inferred = infer_type(expr)?;
Ok(if inferred == InferredType::Table && matches!(&expr.kind, ExprKind::Call(_)) { InferredType::Unknown } else { inferred })
// A `VAR`/`RETURN` block is transparent for this check: its body is what the operator sees,
// so `(VAR d = 1 RETURN LASTDATE('Date'[Date])) - 1` is the same table-valued operand as the
// unwrapped call and must be rejected identically.
let mut inner = expr;
while let ExprKind::VarReturn { body, .. } = &inner.kind {
inner = body;
}
Ok(if inferred == InferredType::Table && matches!(&inner.kind, ExprKind::Call(_)) { InferredType::Unknown } else { inferred })
}
/// Infers the static type of an expression.