Fix formatter crash on bare return in lambda#413
Open
kuruk-mm wants to merge 1 commit intoScony:masterfrom
Open
Fix formatter crash on bare return in lambda#413kuruk-mm wants to merge 1 commit intoScony:masterfrom
kuruk-mm wants to merge 1 commit intoScony:masterfrom
Conversation
The return_stmt handler unconditionally accessed s.children[0], but a bare `return` (without expression) has zero children. This caused an IndexError when formatting lambdas like `func(): return`. The grammar correctly defines return_stmt with an optional expression (`return_stmt: "return" [expr]`), so the formatter now checks for empty children before accessing the list.
db4ecd5 to
4816ef0
Compare
Owner
|
Thanks! Could you please add a test case for that? You can check input/output pairs on how to do this - in such case you just need to add 2 files. As for running tests, please check the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IndexError: list index out of rangewhen formatting a barereturninside a lambda (e.g.func(): return)return_stmthandler infunction_statement_to_str.pyunconditionally accesseds.children[0], but a barereturnhas zero childrenreturn_stmt: "return" [expr]with an optional expression — this fix aligns the formatter with the grammarReproduction
Any GDScript file containing a lambda with a bare return triggers the crash:
Test plan
gdformatno longer crashes on files with barereturnin lambdas