-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes GDScript define nested dictionary and array as constants #50285
- Loading branch information
1 parent
1d21779
commit b3704e6
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
modules/gdscript/tests/scripts/analyzer/errors/invalid_array_index.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Invalid index type "bool" for a base of type "Array". | ||
Cannot get index "true" from "[0, 1]". |
58 changes: 58 additions & 0 deletions
58
modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# https://github.com/godotengine/godot/issues/50285 | ||
|
||
@warning_ignore(unused_local_constant) | ||
func test(): | ||
const CONST_INNER_DICTIONARY = { "key": true } | ||
const CONST_NESTED_DICTIONARY_OLD_WORKAROUND = { | ||
"key1": "value1", | ||
"key2": CONST_INNER_DICTIONARY | ||
} | ||
# All of these should be valid | ||
const CONST_NESTED_DICTIONARY = { | ||
"key1": "value1", | ||
"key2": { "key": true } | ||
} | ||
|
||
|
||
const CONST_DICTIONARY_WITH_ARRAY = { | ||
"key1": [1,2,3,4] | ||
} | ||
|
||
const CONST_NESTED_ARRAY = [[],[2],[1,2,3]] | ||
const CONST_ARRAY_WITH_DICT = [{"key1": 3}, {"key2": 5}] | ||
|
||
const THREE_DIMENSIONAL_ARRAY = [[[],[],[]],[[],[],[]],[[],[],[]]] | ||
const MANY_NESTED_DICT = { | ||
"key1": { | ||
"key11": { | ||
"key111": {}, | ||
"key112": {}, | ||
}, | ||
"key12": { | ||
"key121": {}, | ||
"key122": {}, | ||
}, | ||
}, | ||
"key2": { | ||
"key21": { | ||
"key211": {}, | ||
"key212": {}, | ||
}, | ||
"key22": { | ||
"key221": {}, | ||
"key222": {}, | ||
}, | ||
} | ||
} | ||
|
||
|
||
const CONST_ARRAY_ACCESS = [1,2,3][0] | ||
const CONST_DICT_ACCESS = {"key1": 5}["key1"] | ||
|
||
const CONST_ARRAY_NESTED_ACCESS = [[1,2,3],[4,5,6],[8,9,10]][0][1] | ||
const CONST_DICT_NESTED_ACCESS = {"key1": {"key2": 1}}["key1"]["key2"] | ||
|
||
print(CONST_ARRAY_ACCESS) | ||
print(CONST_DICT_ACCESS) | ||
print(CONST_ARRAY_NESTED_ACCESS) | ||
print(CONST_DICT_NESTED_ACCESS) |
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
GDTEST_OK | ||
1 | ||
5 | ||
2 | ||
1 |