godotengine / godotengine/godot

Parser error on lambda corner case

Open
#97,204 1 comment 0 reactions 0 assignees View on GitHub
bug topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in `master` latest (0a4aedb36065f66fc7e99cb2e6de3e55242f9dfb)

### System information

Ubuntu 24

### Issue description

The following script:
```gdscript
extends Node

func foo():
pass

func _ready() -> void:
get_tree().create_timer(1.0).timeout.connect(foo) # works
get_tree().create_timer(1.0).timeout.connect(func(): foo()) # works
get_tree().create_timer(1.0).timeout.connect(
func():
foo()
) # works
(
get_tree()
. create_timer(1.0)
. timeout
. connect(foo)
) # works
(
get_tree()
. create_timer(1.0)
. timeout
. connect(func(): foo())
) # works
(
get_tree()
. create_timer(1.0)
. timeout
. connect(
func(): foo()
)
) # works
(
get_tree()
. create_timer(1.0)
. timeout
. connect(
func():
foo())
) # works !
(
get_tree()
. create_timer(1.0)
. timeout
. connect(
func():
foo()
)
) # doesn't work !
```

yields
```
SCRIPT ERROR: Parse Error: Unindent doesn't match the previous indentation level.
at: GDScript::reload (res://tests/potential-godot-bugs/lambda_corner_case.gd:47)
ERROR: Failed to load script "res://tests/potential-godot-bugs/lambda_corner_case.gd" with error "Parse error".
at: load (modules/gdscript/gdscript.cpp:3005)
```

while IMO it should parse correctly.

### Steps to reproduce

Run the above using `godot --headless --check-only -s `

### Minimal reproduction project (MRP)

See above.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the final multiline-lambda case with `godot --headless --check-only -s ` and inspect the GDScript path reported at `modules/gdscript/gdscript.cpp:3005`. Trace how the parser handles the closing parenthesis and indentation after the lambda body. Done means the provided script parses without the unindent error and the corner case has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.