summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_analyzer.cpp
diff options
context:
space:
mode:
authorDanil Alexeev <danil@alexeev.xyz>2023-09-29 22:43:56 +0300
committerDanil Alexeev <danil@alexeev.xyz>2023-09-30 13:57:09 +0300
commitba96d4f63160a0c20f35906ecb536dbb2ae53f94 (patch)
tree45cc41f11711f6bf564bdc18286bbcde10d1bdd5 /modules/gdscript/gdscript_analyzer.cpp
parent19890614c6a78ec36030ce65c7da05f07fcdb9ed (diff)
downloadredot-engine-ba96d4f63160a0c20f35906ecb536dbb2ae53f94.tar.gz
GDScript: Fix `UNSAFE_CALL_ARGUMENT` warning for `Variant` constructors
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 882c246706..0d06597bc0 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -3022,9 +3022,23 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
} else {
#ifdef DEBUG_ENABLED
mark_node_unsafe(p_call);
- // We don't know what type was expected since constructors support overloads.
- // TODO: Improve this by checking for matching candidates?
- parser->push_warning(p_call->arguments[0], GDScriptWarning::UNSAFE_CALL_ARGUMENT, "1", function_name, "<unknown type>", "Variant");
+ // Constructors support overloads.
+ Vector<String> types;
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ if (i != builtin_type && Variant::can_convert_strict((Variant::Type)i, builtin_type)) {
+ types.push_back(Variant::get_type_name((Variant::Type)i));
+ }
+ }
+ String expected_types = function_name;
+ if (types.size() == 1) {
+ expected_types += "\" or \"" + types[0];
+ } else if (types.size() >= 2) {
+ for (int i = 0; i < types.size() - 1; i++) {
+ expected_types += "\", \"" + types[i];
+ }
+ expected_types += "\", or \"" + types[types.size() - 1];
+ }
+ parser->push_warning(p_call->arguments[0], GDScriptWarning::UNSAFE_CALL_ARGUMENT, "1", "constructor", function_name, expected_types, "Variant");
#endif
p_call->set_datatype(call_type);
return;
@@ -3069,9 +3083,9 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
#ifdef DEBUG_ENABLED
if (!(par_type.is_variant() && par_type.is_hard_type())) {
GDScriptParser::DataType arg_type = p_call->arguments[i]->get_datatype();
- if (arg_type.is_variant() || !arg_type.is_hard_type() || !is_type_compatible(arg_type, par_type, true)) {
+ if (arg_type.is_variant() || !arg_type.is_hard_type()) {
mark_node_unsafe(p_call);
- parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), function_name, par_type.to_string(), arg_type.to_string_strict());
+ parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), "constructor", function_name, par_type.to_string(), arg_type.to_string_strict());
}
}
#endif
@@ -5057,7 +5071,7 @@ void GDScriptAnalyzer::validate_call_arg(const List<GDScriptParser::DataType> &p
// Argument can be anything, so this is unsafe (unless the parameter is a hard variant).
if (!(par_type.is_hard_type() && par_type.is_variant())) {
mark_node_unsafe(p_call->arguments[i]);
- parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), p_call->function_name, par_type.to_string(), arg_type.to_string_strict());
+ parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), "function", p_call->function_name, par_type.to_string(), arg_type.to_string_strict());
}
#endif
} else if (par_type.is_hard_type() && !is_type_compatible(par_type, arg_type, true)) {
@@ -5069,7 +5083,7 @@ void GDScriptAnalyzer::validate_call_arg(const List<GDScriptParser::DataType> &p
} else {
// Supertypes are acceptable for dynamic compliance, but it's unsafe.
mark_node_unsafe(p_call);
- parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), p_call->function_name, par_type.to_string(), arg_type.to_string_strict());
+ parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), "function", p_call->function_name, par_type.to_string(), arg_type.to_string_strict());
#endif
}
#ifdef DEBUG_ENABLED