mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 04:15:08 +02:00
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:
@ -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);
|
||||
|
@ -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) => {
|
||||
|
Reference in New Issue
Block a user