Reuse Closure type in Value::Closure (#10894)

# Description
Reuses the existing `Closure` type in `Value::Closure`. This will help
with the span refactoring for `Value`. Additionally, this allows us to
more easily box or unbox the `Closure` case should we chose to do so in
the future.

# User-Facing Changes
Breaking API change for `nu_protocol`.
This commit is contained in:
Ian Manske
2023-10-30 22:34:23 +00:00
committed by GitHub
parent d4cbab454e
commit 72cb4b6032
15 changed files with 119 additions and 121 deletions

View File

@ -387,8 +387,8 @@ fn get_converted_value(
if let Ok(v) = env_conversions.follow_cell_path_not_from_user_input(path_members, false) {
let from_span = v.span();
match v {
Value::Closure { val: block_id, .. } => {
let block = engine_state.get_block(block_id);
Value::Closure { val, .. } => {
let block = engine_state.get_block(val.block_id);
if let Some(var) = block.signature.get_positional(0) {
let mut stack = stack.gather_captures(engine_state, &block.captures);

View File

@ -5,7 +5,7 @@ use nu_protocol::{
eval_operator, Argument, Assignment, Bits, Block, Boolean, Call, Comparison, Expr,
Expression, Math, Operator, PathMember, PipelineElement, Redirection,
},
engine::{EngineState, Stack},
engine::{Closure, EngineState, Stack},
IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Range, Record, ShellError, Span,
Spanned, Unit, Value, VarId, ENV_VARIABLE_ID,
};
@ -530,7 +530,13 @@ pub fn eval_expression(
for var_id in &block.captures {
captures.insert(*var_id, stack.get_var(*var_id, expr.span)?);
}
Ok(Value::closure(*block_id, captures, expr.span))
Ok(Value::closure(
Closure {
block_id: *block_id,
captures,
},
expr.span,
))
}
Expr::Block(block_id) => Ok(Value::block(*block_id, expr.span)),
Expr::List(x) => {