"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 trace the extract-function rewrite and its return-type inference, reproduce the anonymous-function case with the existing test framework, then patch and run the focused suite.
- Assistant
The failure is localized: tail-position tracking is updated for named functions and block expressions, but not for anonymous-function bodies. As a result, the final statement inside
fn() { … }is classified as non-tail and the extractor appendsNil. I’m adding the missing scope tracking plus a regression test for the reported selection. - Assistant
The focused regression now produces the correct extracted signature (
-> String) and preserves the tail expression without appendingNil. The initial test run exposed only the expected new snapshot; I’m recording it and then checking the broader extract-function tests and formatting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.