diff options
Diffstat (limited to 'modules')
7 files changed, 15 insertions, 25 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index d7f6126207..f6385dd132 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -879,7 +879,7 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class, current_enum = prev_enum; - dictionary.set_read_only(true); + dictionary.make_read_only(); member.m_enum->set_datatype(enum_type); member.m_enum->dictionary = dictionary; @@ -3892,7 +3892,7 @@ void GDScriptAnalyzer::const_fold_array(GDScriptParser::ArrayNode *p_array, bool array[i] = p_array->elements[i]->reduced_value; } if (p_is_const) { - array.set_read_only(true); + array.make_read_only(); } p_array->is_constant = true; p_array->reduced_value = array; @@ -3919,7 +3919,7 @@ void GDScriptAnalyzer::const_fold_dictionary(GDScriptParser::DictionaryNode *p_d dict[element.key->reduced_value] = element.value->reduced_value; } if (p_is_const) { - dict.set_read_only(true); + dict.make_read_only(); } p_dictionary->is_constant = true; p_dictionary->reduced_value = dict; 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 deleted file mode 100644 index 3e71cd0518..0000000000 --- a/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index ba3e1c46c6..0000000000 --- a/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 7b350e81ad..0000000000 --- a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 3e7ca11a4f..0000000000 --- a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out +++ /dev/null @@ -1,7 +0,0 @@ -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/features/constants_are_read_only.gd b/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.gd new file mode 100644 index 0000000000..d1746979be --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.gd @@ -0,0 +1,10 @@ +const array: Array = [0] +const dictionary := {1: 2} + +@warning_ignore("assert_always_true") +func test(): + assert(array.is_read_only() == true) + assert(str(array) == '[0]') + assert(dictionary.is_read_only() == true) + assert(str(dictionary) == '{ 1: 2 }') + print('ok') diff --git a/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.out b/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok |