summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_analyzer.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-10-16 18:43:11 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-10-16 18:43:11 +0200
commit50212ecfdbd80bdcbb94cc1ad50cd6e7e1c57562 (patch)
treebd04693d3ece3c5e3f850b33b2e3c8de1c8d1f0a /modules/gdscript/gdscript_analyzer.cpp
parenta60fc7f7c86daad48a8b23c9e4e1fe49cf3a0881 (diff)
parent0c2202c56e4c87c53dde17b35c8677974985ae81 (diff)
downloadredot-engine-50212ecfdbd80bdcbb94cc1ad50cd6e7e1c57562.tar.gz
Merge pull request #78882 from dalexeev/gds-fix-utility-func-err-msg
GDScript: Fix incorrect error message for utility functions
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 831971c3f3..0a2dc0f87a 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -3134,12 +3134,16 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
GDScriptUtilityFunctions::get_function(function_name)(&value, (const Variant **)args.ptr(), args.size(), err);
switch (err.error) {
- case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {
- PropertyInfo wrong_arg = function_info.arguments[err.argument];
- push_error(vformat(R"*(Invalid argument for "%s()" function: argument %d should be "%s" but is "%s".)*", function_name, err.argument + 1,
- type_from_property(wrong_arg, true).to_string(), p_call->arguments[err.argument]->get_datatype().to_string()),
- p_call->arguments[err.argument]);
- } break;
+ case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT:
+ if (value.get_type() == Variant::STRING && !value.operator String().is_empty()) {
+ push_error(vformat(R"*(Invalid argument for "%s()" function: %s)*", function_name, value), p_call->arguments[err.argument]);
+ } else {
+ // Do not use `type_from_property()` for expected type, since utility functions use their own checks.
+ push_error(vformat(R"*(Invalid argument for "%s()" function: argument %d should be "%s" but is "%s".)*", function_name, err.argument + 1,
+ Variant::get_type_name((Variant::Type)err.expected), p_call->arguments[err.argument]->get_datatype().to_string()),
+ p_call->arguments[err.argument]);
+ }
+ break;
case Callable::CallError::CALL_ERROR_INVALID_METHOD:
push_error(vformat(R"(Invalid call for function "%s".)", function_name), p_call);
break;
@@ -3181,18 +3185,16 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
Variant::call_utility_function(function_name, &value, (const Variant **)args.ptr(), args.size(), err);
switch (err.error) {
- case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {
- String expected_type_name;
- if (err.argument < function_info.arguments.size()) {
- expected_type_name = type_from_property(function_info.arguments[err.argument], true).to_string();
+ case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT:
+ if (value.get_type() == Variant::STRING && !value.operator String().is_empty()) {
+ push_error(vformat(R"*(Invalid argument for "%s()" function: %s)*", function_name, value), p_call->arguments[err.argument]);
} else {
- expected_type_name = Variant::get_type_name((Variant::Type)err.expected);
+ // Do not use `type_from_property()` for expected type, since utility functions use their own checks.
+ push_error(vformat(R"*(Invalid argument for "%s()" function: argument %d should be "%s" but is "%s".)*", function_name, err.argument + 1,
+ Variant::get_type_name((Variant::Type)err.expected), p_call->arguments[err.argument]->get_datatype().to_string()),
+ p_call->arguments[err.argument]);
}
-
- push_error(vformat(R"*(Invalid argument for "%s()" function: argument %d should be "%s" but is "%s".)*", function_name, err.argument + 1,
- expected_type_name, p_call->arguments[err.argument]->get_datatype().to_string()),
- p_call->arguments[err.argument]);
- } break;
+ break;
case Callable::CallError::CALL_ERROR_INVALID_METHOD:
push_error(vformat(R"(Invalid call for function "%s".)", function_name), p_call);
break;