Skip to main content

eval_block_with_early_return

Function eval_block_with_early_return 

Source
pub fn eval_block_with_early_return<D: DebugContext>(
    engine_state: &EngineState,
    stack: &mut Stack,
    block: &Block,
    input: PipelineData,
) -> Result<PipelineExecutionData, ShellError>
Expand description

Evaluate a block as an early return boundary.

A return is meant to end the command or closure it appears in and go no further. The “boundary” is the point where such a return stops propagating outward and becomes the block’s normal result, instead of escaping to whatever called the command. This function is that point: an early return inside the block produces the block’s result here, exactly like a value in tail position.

Concretely, eval_block runs the block and sets early_return to mark a result that came from a return; this function clears that flag, which is what “absorbs” the return so callers see an ordinary result.

This is used for blocks that return should not escape from, such as custom command bodies and closures: clearing the flag keeps an early return from leaking into the calling block. In contrast, eval_block leaves the flag intact, so its one consumer (top-level file evaluation) can see a top-level return and skip running main.