Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript 2.0: Can't define nested dictionary and array constants #50285

Closed
vntxx opened this issue Jul 8, 2021 · 1 comment · Fixed by #59613
Closed

GDScript 2.0: Can't define nested dictionary and array constants #50285

vntxx opened this issue Jul 8, 2021 · 1 comment · Fixed by #59613

Comments

@vntxx
Copy link

vntxx commented Jul 8, 2021

Godot version

v4.0.dev.calinou [bfc14a6]

System information

Windows 10

Issue description

Upon defining a nested dictionary constant the editor will mark it as an error. It does, however, work when defining the inner dictionary (as a constant) beforehand. Not sure whether this is by design but it did work in GDScript 1.0 (Godot 3.x) so I'm guessing this may be a bug.

Steps to reproduce

Define a nested dictionary as a constant inside a GDScript file (see below)

Minimal reproduction project

Create a new GDScript file inside the engine and paste the following:

const CONST_DICTIONARY = {
	"key1": "value1",
	"key2": "value2",
}

const CONST_NESTED_DICTIONARY = { # Error
	"key1": "value1",
	"key2": { "key": true }
}

const CONST_INNER_DICTIONARY = { "key": true }
const CONST_NESTED_DICTIONARY_WORKAROUND = {
	"key1": "value1",
	"key2": CONST_INNER_DICTIONARY
}
@lyuma
Copy link
Contributor

lyuma commented Aug 25, 2021

It also happens for nested arrays.

Example reproduction case provided by @Scony in #52031

Godot version

master #fb176d5f6e6dc2b43c630a041a8ab7d737173ec4

System information

manjaro linux

Issue description

following script:

const X = {
	'x': [],
}

yields

SCRIPT ERROR: Parse Error: Initializer for a constant must be a constant expression.
          at: GDScript::reload (res://tests/potential-godot-bugs/const-dict.gd:1)
ERROR: Method/function failed. Returning: ERR_PARSE_ERROR
   at: reload (modules/gdscript/gdscript.cpp:840)

while it was working in Godot 3.x

@lyuma lyuma changed the title GDScript 2.0: Can't define nested dictionary constant GDScript 2.0: Can't define nested dictionary and array constants Aug 25, 2021
@akien-mga akien-mga moved this from Todo to In Progress in GDScript Stabilization Tasks Apr 13, 2022
Repository owner moved this from In Progress to Done in GDScript Stabilization Tasks Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants