godot icon indicating copy to clipboard operation
godot copied to clipboard

Lambda requires extra line before End Of File

Open Robert-K opened this issue 1 year ago • 4 comments

Tested versions

  • Reproducible in Godot 4.3

System information

Windows 11, Godot 4.3-stable

Issue description

If I leave a lamda at the end of the file like this (line 12): image The parser throws an error: image However, this is fine (with extra line 13): image

Ignore the fact that I'm doing stupid signal stuff above and causing infinite recursion, that's not a bug that's lack of sleep 💩

Pretty annoying as I frequently write lambdas like this and they happen to be at the EOF.

Steps to reproduce

Open the MRP, issue.gd will not be parsed correctly.

Minimal reproduction project (MRP)

lambda-eof-mrp.zip

Robert-K avatar Aug 28 '24 14:08 Robert-K

I can confirm the issue on Linux (Manjaro KDE Wayland), although to be fair I always have a single empty line at EOF (and the editor adds one automatically if I don't anyway). Also, on my end the error looks different: image This occurs both when the parenthesis is on the same line as the function contents and when it's on its own line as in the screenshot.

Cykyrios avatar Aug 29 '24 05:08 Cykyrios

{E6A61409-D3D7-457A-8D6B-35A6D3E7E8BA} As I just noticed that for the first time: It also happens when everything is inline.

Robert-K avatar Sep 03 '24 14:09 Robert-K

If no one else is on this one, I'll take it. Looks like it might be a good spot to get my feet wet without stepping on too many toes.

jonathansekela avatar Sep 27 '24 01:09 jonathansekela

Still looking into this. Current lead: in GDScriptParser::parse_suite(), lambda_ended gets set to true once and then the function gets hit again. Something tells me this shouldn't happen in this scenario.

jonathansekela avatar Oct 05 '24 04:10 jonathansekela

I'm tapping out on this one. I'm posting my findings here so that someone else can get a head start if they decide to tackle it.

The summary: I've narrowed down the bug to having something to do with the global variables within GDScriptTokenizer::Token GDScriptTokenizerText::scan() in gdscript_tokenizer.cpp. Whether it has to do with the mutation of pending_indents or not, _is_at_end() on line 1443 returns False when there's no newline at the end of the lambda in the MRP, causing make_token(Token::TK_EOF) to not get called. This is the difference between MRP with newline and MRP with no newline.

If anyone has more detailed questions, feel free to ask me. I'll try to give as much guidance as I can.

jonathansekela avatar Dec 11 '24 18:12 jonathansekela