Fix broken constants in scopes (#9679)

This commit is contained in:
Jakub Žádník
2023-07-14 00:02:05 +03:00
committed by GitHub
parent 30904bd095
commit e66139e6bb
8 changed files with 55 additions and 48 deletions

View File

@ -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())