"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 trace the extract-function refactoring path, reproduce the anonymous-function case in the existing test suite, then implement and verify the fix.
- Assistant
The failure is in tail-position tracking: nested block bodies temporarily set their own final statement, but anonymous-function bodies do not. As a result, the last expression inside
fn() { ... }is classified using the enclosing named function’s tail statement and gets the non-tailNilrewrite. I’m adding equivalent scoped tracking for function literals and a regression test for the reported selection. - Assistant
The regression now produces
fn function() -> Stringwith no appendedNil, matching the expression’s actual type. The focused test reached the expected snapshot mismatch (new test baseline); I’m recording that baseline and then running the broader extract-function tests to catch nesting regressions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.