From 5e2ac1a31ee34842438a3a76c54f6a15df77bb95 Mon Sep 17 00:00:00 2001 From: Dmitrii Maganov Date: Sun, 8 Jan 2023 05:41:06 +0200 Subject: GDScript: Begin making constants deep, not shallow or flat --- .../tests/scripts/analyzer/errors/constant_array_index_assign.gd | 5 +++++ .../tests/scripts/analyzer/errors/constant_array_index_assign.out | 2 ++ .../scripts/analyzer/errors/constant_dictionary_index_assign.gd | 5 +++++ .../scripts/analyzer/errors/constant_dictionary_index_assign.out | 2 ++ .../tests/scripts/runtime/errors/constant_array_is_deep.gd | 6 ++++++ .../tests/scripts/runtime/errors/constant_array_is_deep.out | 6 ++++++ .../tests/scripts/runtime/errors/constant_array_push_back.gd | 4 ++++ .../tests/scripts/runtime/errors/constant_array_push_back.out | 7 +++++++ .../tests/scripts/runtime/errors/constant_dictionary_erase.gd | 4 ++++ .../tests/scripts/runtime/errors/constant_dictionary_erase.out | 7 +++++++ .../tests/scripts/runtime/errors/constant_dictionary_is_deep.gd | 6 ++++++ .../tests/scripts/runtime/errors/constant_dictionary_is_deep.out | 6 ++++++ 12 files changed, 60 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.out create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.out create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out (limited to 'modules/gdscript/tests') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.gd b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.gd new file mode 100644 index 0000000000..b8603dd4ca --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.gd @@ -0,0 +1,5 @@ +const array: Array = [0] + +func test(): + var key: int = 0 + array[key] = 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.out b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.out new file mode 100644 index 0000000000..5275183da2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot assign a new value to a constant. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.gd b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.gd new file mode 100644 index 0000000000..9b5112b788 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.gd @@ -0,0 +1,5 @@ +const dictionary := {} + +func test(): + var key: int = 0 + dictionary[key] = 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.out b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.out new file mode 100644 index 0000000000..5275183da2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot assign a new value to a constant. diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.gd new file mode 100644 index 0000000000..a5ecaba38d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.gd @@ -0,0 +1,6 @@ +const array: Array = [{}] + +func test(): + var dictionary := array[0] + var key: int = 0 + dictionary[key] = 0 diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out new file mode 100644 index 0000000000..2a97eaea44 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/constant_array_is_deep.gd +>> 6 +>> Invalid set index '0' (on base: 'Dictionary') with value of type 'int' diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd new file mode 100644 index 0000000000..3e71cd0518 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd @@ -0,0 +1,4 @@ +const array: Array = [0] + +func test(): + array.push_back(0) diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out new file mode 100644 index 0000000000..ba3e1c46c6 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out @@ -0,0 +1,7 @@ +GDTEST_RUNTIME_ERROR +>> ERROR +>> on function: push_back() +>> core/variant/array.cpp +>> 253 +>> Condition "_p->read_only" is true. +>> Array is in read-only state. diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd new file mode 100644 index 0000000000..935fb773dc --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd @@ -0,0 +1,4 @@ +const dictionary := {} + +func test(): + dictionary.erase(0) diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out new file mode 100644 index 0000000000..3e7ca11a4f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out @@ -0,0 +1,7 @@ +GDTEST_RUNTIME_ERROR +>> ERROR +>> on function: erase() +>> core/variant/dictionary.cpp +>> 177 +>> Condition "_p->read_only" is true. Returning: false +>> Dictionary is in read-only state. diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.gd new file mode 100644 index 0000000000..4763210a7f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.gd @@ -0,0 +1,6 @@ +const dictionary := {0: [0]} + +func test(): + var array := dictionary[0] + var key: int = 0 + array[key] = 0 diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out new file mode 100644 index 0000000000..c807db6b0c --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/constant_dictionary_is_deep.gd +>> 6 +>> Invalid set index '0' (on base: 'Array') with value of type 'int' -- cgit v1.2.3