"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:
gleamfn wibble() { let wobble = fn() { echo "wibble" echo "wobble" // extracting this line } }is turned into
gleamfn 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 logic and how it handles anonymous functions.
- Assistant
Implementing the fix:
visit_typed_expr_blockupdateslast_statement_location, but anonymous function bodies don't — so tail statements inside them are misclassified as non-tail and get an incorrectNilreturn. - Assistant
Updating tests to use selection patterns that match existing extract-function tests.
- Assistant
Implemented the fix for this bug. The root cause was that
ExtractFunctiontracked tail position for blocks viavisit_typed_expr_block, but not for anonymous function bodies.Root cause
When determining whether an extracted statement is in tail position,
ExtractFunctioncompares it againstlast_statement_location. That field was updated when entering a block expression, but not when entering an anonymous function (fn() { ... }).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.