godotengine / godotengine/godot

Unexpected lambda indentation error

Open
#116,133 2 comments 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: v4.6.stable

### System information

Godot v4.6.stable unknown - Arch Linux #1 SMP PREEMPT_DYNAMIC Fri, 06 Feb 2026 06:47:20 +0000 on X11 - X11 display driver, Single-window, 2 monitors - OpenGL 3 (Compatibility) - NVIDIA GeForce RTX 3060 Ti (nvidia; 590.48.01) - 13th Gen Intel(R) Core(TM) i5-13400F (16 threads) - 15.37 GiB memory

### Issue description

```gdscript
# I have an array of Item objects that needs to be converted to dicts for serialization.
class Item:
var name: String
var progress: float

var items: Array[Item]

# This works:
var simple := items.map(func (e: Item): return { "name": e.name, "progress": e.progress })

# A properly indented version also works:
var simple := items.map(
func (e: Item):
return {
"name": e.name,
"progress": e.progress,
}
)

# But in practice, I need to wrap the array inside another dict.
# This works:
var wrapped := {
"items": items.map(func (e: Item): return { "name": e.name, "progress": e.progress })
}

# But this doesn't:
var wrapped := {
"items": items.map(
func (e: Item):
return {
"name": e.name,
"progress": e.progress,
} # <-- Parse Error: Unindent doesn't match the previous indentation level
)
}
```

I played around with the indentations and failed to find a way to make the compiler happy.

But in the end, I don't see anything wrong with the indentation in the last snippet. It's basically the same as the "simple" version.

### Steps to reproduce

See issue description.

### Minimal reproduction project (MRP)

script.gd

```gdscript
@tool
extends EditorScript

class Item:
var name: String
var progress: float

func _run() -> void:
var items: Array[Item]
for i in 5:
var item := Item.new()
item.name = "Item #%d" % i
item.progress = randf()
items.append(item)

#var simple := items.map(func (e: Item): return { "name": e.name, "progress": e.progress })
var simple := items.map(
func (e: Item):
return {
"name": e.name,
"progress": e.progress,
}
)
print(simple)

#var wrapped := {
#"items": items.map(func (e: Item): return { "name": e.name, "progress": e.progress })
#}
#var wrapped := {
#"items": items.map(
#func (e: Item):
#return {
#"name": e.name,
#"progress": e.progress,
#}
#)
#}
#print(dict)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.