"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
I'll search the codebase for the extract-function refactoring logic and how it handles return types inside anonymous functions.
- Assistant
The bug is extracting code inside an anonymous function body, not extracting the whole anonymous function. I'll trace that path and how return types are inferred.
- Assistant
The issue is that
last_statement_locationisn't set for anonymous function bodies, so tail statements are misclassified. I'll addvisit_typed_expr_fnmirroringvisit_typed_expr_blockand a regression test. - Assistant
Implementing the fix and adding a regression test.
- Assistant
Vec1::last()returns the element directly, not anOption— fixing that. - Assistant
Zero-width
.to_selection()is rejected by the extract-function action. Updating the test to use a proper range. - Assistant
The selection matched the wrong
wobble— tightening the test range. - Assistant
The fix works — no trailing
Nil. Accepting the snapshot and running related tests. - Assistant
Implemented the fix for the "Extract function" bug when extracting from inside an anonymous function.
Root cause
ExtractFunctiontracked tail position vialast_statement_locationin named functions (visit_typed_function) and blocks (visit_typed_expr_block), but not in anonymous function bodies. Those bodies are visited throughvisit_typed_expr_fn, which never updatedlast_statement_location.So a tail statement like
echo "wobble"insidefn() { ... }was treated as non-tail, and appended a spurious at the end.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.