forked from extern/nushell
ensure that when nu evaluates files, it allows early returns (#7415)
# Description Fixes #7301. # User-Facing Changes `return` can now be used in scripts without explicit `def main`. # Tests + Formatting Don't forget to add tests that cover your changes. (I'm not sure how to test this.) Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use nu_engine::{eval_block, CallExt};
|
||||
use nu_engine::{eval_block_with_early_return, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type};
|
||||
@ -48,7 +48,7 @@ impl Command for Source {
|
||||
let block_id: i64 = call.req_parser_info(engine_state, stack, 0)?;
|
||||
|
||||
let block = engine_state.get_block(block_id as usize).clone();
|
||||
eval_block(
|
||||
eval_block_with_early_return(
|
||||
engine_state,
|
||||
stack,
|
||||
&block,
|
||||
|
4
crates/nu-command/src/env/source_env.rs
vendored
4
crates/nu-command/src/env/source_env.rs
vendored
@ -1,6 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use nu_engine::{eval_block, find_in_dirs_env, redirect_env, CallExt};
|
||||
use nu_engine::{eval_block_with_early_return, find_in_dirs_env, redirect_env, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
@ -62,7 +62,7 @@ impl Command for SourceEnv {
|
||||
let block = engine_state.get_block(block_id as usize).clone();
|
||||
let mut callee_stack = caller_stack.gather_captures(&block.captures);
|
||||
|
||||
let result = eval_block(
|
||||
let result = eval_block_with_early_return(
|
||||
engine_state,
|
||||
&mut callee_stack,
|
||||
&block,
|
||||
|
Reference in New Issue
Block a user