IR: Don't generate instructions for def and export def. (#14114)

# Description
Fixes: #14110
Fixes: #14087

I think it's ok to not generating instruction to `def` and `export def`
call. Because they just return `PipelineData::Empty` without doing
anything.

If nushell generates instructions for `def` and `export def`, nushell
will try to capture variables for these block. It's not the time to do
this.

# User-Facing Changes
```
nu -c "
def bar [] {
    let x = 1
    ($x | foo)
}
def foo [] {
    foo
}
" 
```
Will no longer raise error.

# Tests + Formatting
Added 4 tests
This commit is contained in:
Wind
2024-11-07 13:35:00 +08:00
committed by GitHub
parent b6eda33438
commit b7af715f6b
2 changed files with 37 additions and 0 deletions

View File

@ -71,6 +71,9 @@ pub(crate) fn compile_call(
"return" => {
return compile_return(working_set, builder, call, redirect_modes, io_reg);
}
"def" | "export def" => {
return builder.load_empty(io_reg);
}
_ => (),
}
}