mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 22:47:43 +02:00
preserve variable capture spans in blocks (#15334)
Closes #15160 # User-Facing Changes Certain "variable not found" errors no longer highlight the surrounding block. Before: ```nushell do { match foo { _ => $in } } Error: nu:🐚:variable_not_found × Variable not found ╭─[entry #1:1:1] 1 │ ╭─▶ do { 2 │ │ match foo { 3 │ │ _ => $in 4 │ │ } 5 │ ├─▶ } · ╰──── variable not found ``` After: ```nushell Error: nu:🐚:variable_not_found × Variable not found ╭─[entry #1:3:10] 2 │ match foo { 3 │ _ => $in · ─┬─ · ╰── variable not found ```
This commit is contained in:
@ -642,17 +642,17 @@ impl Eval for EvalRuntime {
|
||||
.get_block(block_id)
|
||||
.captures
|
||||
.iter()
|
||||
.map(|&id| {
|
||||
.map(|(id, span)| {
|
||||
stack
|
||||
.get_var(id, span)
|
||||
.get_var(*id, *span)
|
||||
.or_else(|_| {
|
||||
engine_state
|
||||
.get_var(id)
|
||||
.get_var(*id)
|
||||
.const_val
|
||||
.clone()
|
||||
.ok_or(ShellError::VariableNotFoundAtRuntime { span })
|
||||
.ok_or(ShellError::VariableNotFoundAtRuntime { span: *span })
|
||||
})
|
||||
.map(|var| (id, var))
|
||||
.map(|var| (*id, var))
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
|
@ -857,7 +857,7 @@ fn literal_value(
|
||||
let captures = block
|
||||
.captures
|
||||
.iter()
|
||||
.map(|var_id| get_var(ctx, *var_id, span).map(|val| (*var_id, val)))
|
||||
.map(|(var_id, span)| get_var(ctx, *var_id, *span).map(|val| (*var_id, val)))
|
||||
.collect::<Result<Vec<_>, ShellError>>()?;
|
||||
Value::closure(
|
||||
Closure {
|
||||
|
Reference in New Issue
Block a user