godotengine / godotengine/godot
[GDScript] Cannot declare variable in lambda with the same name as parent scope
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Godot v4.3.stable - Windows 10.0.26100 - Vulkan (Forward+) - integrated Intel(R) Iris(R) Xe Graphics (Intel Corporation; 31.0.101.5595) - 13th Gen Intel(R) Core(TM) i5-1340P (16 Threads)
### System information
N/A
### Issue description
When creating a GDScript function containing a lambda in it, both with the same variable name, this will result in a compile error.
### Steps to reproduce
Create the following script below. It will result in the following error:
```
Parse Error: There is already a variable named "result" declared in this scope.
```
### Minimal reproduction project (MRP)
```gdscript
func test() -> void:
var result := []
var lambda := func () -> void:
var result := []
```
Contributor guide
Research direction
Start by running the minimal GDScript reproduction from the issue and confirming the scope error. Trace the GDScript compiler's handling of variable declarations in nested lambdas, then add or update a regression test for the shown case. Done means the script parses successfully while preserving errors for invalid duplicate declarations.
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