summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp6
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd7
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out2
3 files changed, 11 insertions, 4 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 81e50d6b79..1149749ef7 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -1595,7 +1595,7 @@ void GDScriptAnalyzer::resolve_constant(GDScriptParser::ConstantNode *p_constant
}
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);
#ifdef DEBUG_ENABLED
} 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) {
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) {
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.
valid = false;
} 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);
}
}
}
diff --git a/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd
index 4511c3d10b..eb0003eed8 100644
--- a/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd
+++ b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd
@@ -1,4 +1,11 @@
+
+var m_string_array: Array[String] = [&"abc"]
+var m_stringname_array: Array[StringName] = ["abc"]
+
func test():
+ print(m_string_array)
+ print(m_stringname_array)
+
# Converted to String when initialized
var string_array: Array[String] = [&"abc"]
print(string_array)
diff --git a/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out
index 70dd01d88e..09c199bde1 100644
--- a/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out
+++ b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out
@@ -1,3 +1,5 @@
GDTEST_OK
["abc"]
[&"abc"]
+["abc"]
+[&"abc"]