Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the panic when using externs + subexpression #4799

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Fixes the panic when using externs + string interpolation
  • Loading branch information
sophiajt committed Mar 9, 2022
commit 8a7e6e752e745409181b490cf40fad3adb645b04
11 changes: 9 additions & 2 deletions crates/nu-parser/src/known_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ impl Command for KnownExternal {
) -> Result<PipelineData, ShellError> {
// FIXME: This is a bit of a hack, and it'd be nice for the parser/AST to be able to handle the original
// order of the parameters. Until then, we need to recover the original order.

// FIXME: This is going to be a bit expensive, but we need to do it to ensure any new block/subexpression
// we find when parsing the external call is handled properly.
let mut engine_state = engine_state.clone();

let call_span = call.span();
let contents = engine_state.get_span_contents(&call_span);

Expand All @@ -45,8 +50,10 @@ impl Command for KnownExternal {
let (lexed, _) = crate::lex(contents, call_span.start, &[], &[], true);

let spans: Vec<_> = lexed.into_iter().map(|x| x.span).collect();
let mut working_set = StateWorkingSet::new(engine_state);
let mut working_set = StateWorkingSet::new(&engine_state);
let (external_call, _) = crate::parse_external_call(&mut working_set, &spans);
let delta = working_set.render();
engine_state.merge_delta(delta, None, ".")?;

match external_call.expr {
Expr::ExternalCall(head, args) => {
Expand Down Expand Up @@ -84,7 +91,7 @@ impl Command for KnownExternal {
))
}

command.run(engine_state, stack, &call, input)
command.run(&engine_state, stack, &call, input)
}
x => {
println!("{:?}", x);
Expand Down