You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-14 13:41:12 +00:00
Fix String type compatibility being too permissive
This commit is contained in:
@@ -1595,7 +1595,7 @@ void GDScriptAnalyzer::resolve_constant(GDScriptParser::ConstantNode *p_constant
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p_constant->datatype_specifier != nullptr) {
|
if (p_constant->datatype_specifier != nullptr) {
|
||||||
if (!is_type_compatible(explicit_type, type)) {
|
if (!is_type_compatible(explicit_type, type, true)) {
|
||||||
push_error(vformat(R"(Assigned value for constant "%s" has type %s which is not compatible with defined type %s.)", p_constant->identifier->name, type.to_string(), explicit_type.to_string()), p_constant->initializer);
|
push_error(vformat(R"(Assigned value for constant "%s" has type %s which is not compatible with defined type %s.)", p_constant->identifier->name, type.to_string(), explicit_type.to_string()), p_constant->initializer);
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
} else if (explicit_type.builtin_type == Variant::INT && type.builtin_type == Variant::FLOAT) {
|
} else if (explicit_type.builtin_type == Variant::INT && type.builtin_type == Variant::FLOAT) {
|
||||||
@@ -4187,8 +4187,6 @@ bool GDScriptAnalyzer::is_type_compatible(const GDScriptParser::DataType &p_targ
|
|||||||
|
|
||||||
if (p_target.kind == GDScriptParser::DataType::BUILTIN) {
|
if (p_target.kind == GDScriptParser::DataType::BUILTIN) {
|
||||||
bool valid = p_source.kind == GDScriptParser::DataType::BUILTIN && p_target.builtin_type == p_source.builtin_type;
|
bool valid = p_source.kind == GDScriptParser::DataType::BUILTIN && p_target.builtin_type == p_source.builtin_type;
|
||||||
valid |= p_source.builtin_type == Variant::STRING && p_target.builtin_type == Variant::STRING_NAME;
|
|
||||||
valid |= p_source.builtin_type == Variant::STRING_NAME && p_target.builtin_type == Variant::STRING;
|
|
||||||
if (!valid && p_allow_implicit_conversion) {
|
if (!valid && p_allow_implicit_conversion) {
|
||||||
valid = Variant::can_convert_strict(p_source.builtin_type, p_target.builtin_type);
|
valid = Variant::can_convert_strict(p_source.builtin_type, p_target.builtin_type);
|
||||||
}
|
}
|
||||||
@@ -4204,7 +4202,7 @@ bool GDScriptAnalyzer::is_type_compatible(const GDScriptParser::DataType &p_targ
|
|||||||
// Variant array can't be appended to typed array.
|
// Variant array can't be appended to typed array.
|
||||||
valid = false;
|
valid = false;
|
||||||
} else {
|
} else {
|
||||||
valid = is_type_compatible(p_target.get_container_element_type(), p_source.get_container_element_type(), false);
|
valid = is_type_compatible(p_target.get_container_element_type(), p_source.get_container_element_type(), p_allow_implicit_conversion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
|
|
||||||
|
var m_string_array: Array[String] = [&"abc"]
|
||||||
|
var m_stringname_array: Array[StringName] = ["abc"]
|
||||||
|
|
||||||
func test():
|
func test():
|
||||||
|
print(m_string_array)
|
||||||
|
print(m_stringname_array)
|
||||||
|
|
||||||
# Converted to String when initialized
|
# Converted to String when initialized
|
||||||
var string_array: Array[String] = [&"abc"]
|
var string_array: Array[String] = [&"abc"]
|
||||||
print(string_array)
|
print(string_array)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
GDTEST_OK
|
GDTEST_OK
|
||||||
["abc"]
|
["abc"]
|
||||||
[&"abc"]
|
[&"abc"]
|
||||||
|
["abc"]
|
||||||
|
[&"abc"]
|
||||||
|
|||||||
Reference in New Issue
Block a user