mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-01 18:26:05 -06:00
dax: document the variable index and look through VAR/RETURN in operand checks (#2228)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user