Merge pull request #53843 from vnen/gdscript-typed-array-subscript-constant

Fix inferred typed array marked as constant
This commit is contained in:
Rémi Verschelde 2021-10-15 16:49:29 +02:00 committed by GitHub
commit 3f888966c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View file

@ -471,6 +471,7 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
if (container_type.kind != GDScriptParser::DataType::VARIANT) { if (container_type.kind != GDScriptParser::DataType::VARIANT) {
container_type.is_meta_type = false; container_type.is_meta_type = false;
container_type.is_constant = false;
result.set_container_element_type(container_type); result.set_container_element_type(container_type);
} }
} }
@ -1802,6 +1803,7 @@ void GDScriptAnalyzer::update_array_literal_element_type(const GDScriptParser::D
} }
} }
if (all_same_type) { if (all_same_type) {
element_type.is_constant = false;
array_type.set_container_element_type(element_type); array_type.set_container_element_type(element_type);
} else if (all_have_type) { } else if (all_have_type) {
push_error(vformat(R"(Variant array is not compatible with an array of type "%s".)", p_base_type.get_container_element_type().to_string()), p_array_literal); push_error(vformat(R"(Variant array is not compatible with an array of type "%s".)", p_base_type.get_container_element_type().to_string()), p_array_literal);
@ -3498,6 +3500,7 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_property(const PropertyInfo
} else { } else {
ERR_FAIL_V_MSG(result, "Could not find element type from property hint of a typed array."); ERR_FAIL_V_MSG(result, "Could not find element type from property hint of a typed array.");
} }
elem_type.is_constant = false;
result.set_container_element_type(elem_type); result.set_container_element_type(elem_type);
} }
} }

View file

@ -0,0 +1,6 @@
# https://github.com/godotengine/godot/issues/53640
func test():
var arr := [0]
arr[0] = 1
print(arr[0])