diff --git a/crates/nu-engine/src/scope.rs b/crates/nu-engine/src/scope.rs index ba8f427035..2bd29868c4 100644 --- a/crates/nu-engine/src/scope.rs +++ b/crates/nu-engine/src/scope.rs @@ -100,7 +100,7 @@ impl<'e, 's> ScopeData<'e, 's> { record! { "description" => Value::string(x.description, span), "example" => Value::string(x.example, span), - "result" => x.result.unwrap_or(Value::nothing(span)), + "result" => x.result.unwrap_or(Value::nothing(span)).with_span(span), }, span, ) diff --git a/tests/scope/mod.rs b/tests/scope/mod.rs index ffcaa80bd7..83f9ee5b82 100644 --- a/tests/scope/mod.rs +++ b/tests/scope/mod.rs @@ -330,3 +330,19 @@ fn correct_scope_variables_fields() { let actual = nu!(&inp.join("; ")); assert_eq!(actual.out, "false"); } + +#[test] +fn example_results_have_valid_span() { + let inp = &[ + "scope commands", + "| where name == 'do'", + "| first", + "| get examples", + "| where result == 177", + "| get 0.result", + "| metadata", + "| view span $in.span.start $in.span.end", + ]; + let actual = nu!(&inp.join(" ")); + assert_eq!(actual.out, "scope commands"); +}