mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:15:41 +02:00
Fix broken constants in scopes (#9679)
This commit is contained in:
@ -47,15 +47,17 @@ impl Command for Const {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let var_id = call
|
||||
.positional_nth(0)
|
||||
.expect("checked through parser")
|
||||
.as_var()
|
||||
.expect("internal error: missing variable");
|
||||
let var_id = if let Some(id) = call.positional_nth(0).and_then(|pos| pos.as_var()) {
|
||||
id
|
||||
} else {
|
||||
return Err(ShellError::NushellFailedSpanned {
|
||||
msg: "Could not get variable".to_string(),
|
||||
label: "variable not added by the parser".to_string(),
|
||||
span: call.head,
|
||||
});
|
||||
};
|
||||
|
||||
if let Some(constval) = engine_state.find_constant(var_id, &[]) {
|
||||
// Instead of creating a second copy of the value in the stack, we could change
|
||||
// stack.get_var() to check engine_state.find_constant().
|
||||
if let Some(constval) = &engine_state.get_var(var_id).const_val {
|
||||
stack.add_var(var_id, constval.clone());
|
||||
|
||||
Ok(PipelineData::empty())
|
||||
|
Reference in New Issue
Block a user