Skip to content

Commit

Permalink
Fixes the panic when using externs + string interpolation (#4799)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiajt committed Mar 9, 2022
1 parent be43b3c commit 3bdd924
Showing 1 changed file with 9 additions and 2 deletions.
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

0 comments on commit 3bdd924

Please sign in to comment.