Skip to content

Lambda functions inside parenthesis inside an argument list result into invalid syntax #287

Description

@CosmoMyzrailGorynych

Godot 4.7.1, plugin version 0.22.0. (The formatter was run through CLI)

I wish this syntax worked, too, but unfortunately such formatting is not supported:

-	CheatPanel.add_cheat(&'heal_hero', 'Heal the hero', (func() -> void: health = max_health), self)
+	CheatPanel.add_cheat(
+		&'heal_hero',
+		'Heal the hero',
+		(func() -> void:
+			health = max_health
+		),
+		self,
+	)
Image

Valid formatting example:

	CheatPanel.add_cheat(
		&'toggle_godmode',
		'Toggle godmode',
		(func() -> void:
			god_mode = !god_mode
			),
		self,
	)

or maybeeee

	CheatPanel.add_cheat(
		&'heal_hero',
		'Heal the hero',
		(func() -> void:
			health = max_health
			)
		,
		self,
	)

The parentheses around the lambda function can be dropped. (They were there initially to separate the function body from the 4th argument self: otherwise the , operator is parsed as the continuation of the function body.) But the trailing comma is quite error-prone.

	CheatPanel.add_cheat(
		&'heal_hero',
		'Heal the hero',
		func() -> void:
			health = max_health, # ← Easy to miss/erase
		self,
	)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions