"Extract function" incorrectly returns Nil when extracting from anonymous function <!--…
- User
"Extract function" incorrectly returns
Nilwhen extracting from anonymous functionWhen trying to extract a function from within an anonymous function, the extracted function always returns
Nil, even when incorrect.For example:
fn wibble() { let wobble = fn() { echo "wibble" echo "wobble" // extracting this line } }is turned into
fn wibble() { let wobble = fn() { echo "wibble" function() } } fn function() -> Nil { echo "wobble" Nil // this is incorrect! }I have a fix for it.
Interface
No new interfaces are introduced.
- Assistant
Investigating the "Extract function" refactoring to find why it returns
Nilwhen extracting from anonymous functions. - Assistant
Implementing the fix:
ExtractFunctiontracks tail position for blocks but not anonymous function bodies, so tail statements insidefn()are treated as non-tail and get an incorrect explicitNil. - Assistant
The fix works — the extracted function no longer has an explicit
Nil. Accepting snapshots. - Assistant
Implemented the fix for the "Extract function" bug when extracting from inside an anonymous function.
Root cause
ExtractFunctiontrackslast_statement_locationto decide whether extracted statements are in tail position (return their value) or not (append explicitNil). That tracking was set up for:- module-level functions (
visit_typed_function) - blocks (
visit_typed_expr_block)
but not for anonymous function bodies. So a statement like
echo "wobble"at the end offn() { ... }was treated as non-tail, andextract_statementsincorrectly appended . - module-level functions (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.