summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/input/input.cpp8
-rw-r--r--core/input/input.h2
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp42
-rw-r--r--modules/gdscript/gdscript_parser.h2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.gd14
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.gd15
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.gd14
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.gd15
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out2
13 files changed, 101 insertions, 21 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index f3f5940118..2d48bdd4cf 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -1095,7 +1095,8 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
return;
}
- JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value);
+ JoyAxisRange range;
+ JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value, range);
if (map.type == TYPE_BUTTON) {
bool pressed = map.value > 0.5;
@@ -1135,7 +1136,7 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
if (map.type == TYPE_AXIS) {
JoyAxis axis = JoyAxis(map.index);
float value = map.value;
- if (axis == JoyAxis::TRIGGER_LEFT || axis == JoyAxis::TRIGGER_RIGHT) {
+ if (range == FULL_AXIS && (axis == JoyAxis::TRIGGER_LEFT || axis == JoyAxis::TRIGGER_RIGHT)) {
// Convert to a value between 0.0f and 1.0f.
value = 0.5f + value / 2.0f;
}
@@ -1241,7 +1242,7 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping,
return event;
}
-Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value) {
+Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value, JoyAxisRange &r_range) {
JoyEvent event;
for (int i = 0; i < mapping.bindings.size(); i++) {
@@ -1287,6 +1288,7 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, J
case TYPE_AXIS:
event.index = (int)binding.output.axis.axis;
event.value = value;
+ r_range = binding.output.axis.range;
if (binding.output.axis.range != binding.input.axis.range) {
switch (binding.output.axis.range) {
case POSITIVE_HALF_AXIS:
diff --git a/core/input/input.h b/core/input/input.h
index 8ce5f64a6a..bedc3fa0e3 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -221,7 +221,7 @@ private:
Vector<JoyDeviceMapping> map_db;
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button);
- JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value);
+ JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value, JoyAxisRange &r_range);
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[(size_t)HatDir::MAX]);
JoyButton _get_output_button(String output);
JoyAxis _get_output_axis(String output);
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 2439e5760c..983a19470a 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -1585,7 +1585,13 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *
GDScriptParser::FunctionNode *previous_function = parser->current_function;
parser->current_function = p_function;
bool previous_static_context = static_context;
- static_context = p_function->is_static;
+ if (p_is_lambda) {
+ // For lambdas this is determined from the context, the `static` keyword is not allowed.
+ p_function->is_static = static_context;
+ } else {
+ // For normal functions, this is determined in the parser by the `static` keyword.
+ static_context = p_function->is_static;
+ }
GDScriptParser::DataType prev_datatype = p_function->get_datatype();
@@ -3317,15 +3323,16 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
}
if (is_self && static_context && !method_flags.has_flag(METHOD_FLAG_STATIC)) {
- if (parser->current_function) {
- // Get the parent function above any lambda.
- GDScriptParser::FunctionNode *parent_function = parser->current_function;
- while (parent_function->source_lambda) {
- parent_function = parent_function->source_lambda->parent_function;
- }
+ // Get the parent function above any lambda.
+ GDScriptParser::FunctionNode *parent_function = parser->current_function;
+ while (parent_function && parent_function->source_lambda) {
+ parent_function = parent_function->source_lambda->parent_function;
+ }
+
+ if (parent_function) {
push_error(vformat(R"*(Cannot call non-static function "%s()" from static function "%s()".)*", p_call->function_name, parent_function->identifier->name), p_call);
} else {
- push_error(vformat(R"*(Cannot call non-static function "%s()" for static variable initializer.)*", p_call->function_name), p_call);
+ push_error(vformat(R"*(Cannot call non-static function "%s()" from a static variable initializer.)*", p_call->function_name), p_call);
}
} else if (!is_self && base_type.is_meta_type && !method_flags.has_flag(METHOD_FLAG_STATIC)) {
base_type.is_meta_type = false; // For `to_string()`.
@@ -3908,15 +3915,16 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
bool source_is_variable = p_identifier->source == GDScriptParser::IdentifierNode::MEMBER_VARIABLE || p_identifier->source == GDScriptParser::IdentifierNode::INHERITED_VARIABLE;
bool source_is_signal = p_identifier->source == GDScriptParser::IdentifierNode::MEMBER_SIGNAL;
if ((source_is_variable || source_is_signal) && static_context) {
- if (parser->current_function) {
- // Get the parent function above any lambda.
- GDScriptParser::FunctionNode *parent_function = parser->current_function;
- while (parent_function->source_lambda) {
- parent_function = parent_function->source_lambda->parent_function;
- }
+ // Get the parent function above any lambda.
+ GDScriptParser::FunctionNode *parent_function = parser->current_function;
+ while (parent_function && parent_function->source_lambda) {
+ parent_function = parent_function->source_lambda->parent_function;
+ }
+
+ if (parent_function) {
push_error(vformat(R"*(Cannot access %s "%s" from the static function "%s()".)*", source_is_signal ? "signal" : "instance variable", p_identifier->name, parent_function->identifier->name), p_identifier);
} else {
- push_error(vformat(R"*(Cannot access %s "%s" for a static variable initializer.)*", source_is_signal ? "signal" : "instance variable", p_identifier->name), p_identifier);
+ push_error(vformat(R"*(Cannot access %s "%s" from a static variable initializer.)*", source_is_signal ? "signal" : "instance variable", p_identifier->name), p_identifier);
}
}
@@ -5459,12 +5467,15 @@ void GDScriptAnalyzer::resolve_pending_lambda_bodies() {
}
GDScriptParser::LambdaNode *previous_lambda = current_lambda;
+ bool previous_static_context = static_context;
List<GDScriptParser::LambdaNode *> lambdas = pending_body_resolution_lambdas;
pending_body_resolution_lambdas.clear();
for (GDScriptParser::LambdaNode *lambda : lambdas) {
current_lambda = lambda;
+ static_context = lambda->function->is_static;
+
resolve_function_body(lambda->function, true);
int captures_amount = lambda->captures.size();
@@ -5493,6 +5504,7 @@ void GDScriptAnalyzer::resolve_pending_lambda_bodies() {
}
current_lambda = previous_lambda;
+ static_context = previous_static_context;
}
bool GDScriptAnalyzer::class_exists(const StringName &p_class) const {
diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h
index 62a2f4f98c..9067864dfe 100644
--- a/modules/gdscript/gdscript_parser.h
+++ b/modules/gdscript/gdscript_parser.h
@@ -838,7 +838,7 @@ public:
HashMap<StringName, int> parameters_indices;
TypeNode *return_type = nullptr;
SuiteNode *body = nullptr;
- bool is_static = false;
+ bool is_static = false; // For lambdas it's determined in the analyzer.
bool is_coroutine = false;
Variant rpc_config;
MethodInfo info;
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.gd
new file mode 100644
index 0000000000..a98f69f3ac
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.gd
@@ -0,0 +1,14 @@
+# GH-83468
+
+func non_static_func():
+ pass
+
+static func static_func():
+ var f := func ():
+ var g := func ():
+ non_static_func()
+ g.call()
+ f.call()
+
+func test():
+ pass
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out
new file mode 100644
index 0000000000..b78f131345
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Cannot call non-static function "non_static_func()" from static function "static_func()".
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.gd
new file mode 100644
index 0000000000..7af9ff274c
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.gd
@@ -0,0 +1,15 @@
+# GH-83468
+
+func non_static_func():
+ pass
+
+static func static_func(
+ f := func ():
+ var g := func ():
+ non_static_func()
+ g.call()
+):
+ f.call()
+
+func test():
+ pass
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out
new file mode 100644
index 0000000000..b78f131345
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Cannot call non-static function "non_static_func()" from static function "static_func()".
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.gd
new file mode 100644
index 0000000000..5130973bd2
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.gd
@@ -0,0 +1,14 @@
+# GH-83468
+
+func non_static_func():
+ pass
+
+static var static_var = func ():
+ var f := func ():
+ var g := func ():
+ non_static_func()
+ g.call()
+ f.call()
+
+func test():
+ pass
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.out
new file mode 100644
index 0000000000..c0308c81f3
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Cannot call non-static function "non_static_func()" from a static variable initializer.
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.gd
new file mode 100644
index 0000000000..2d15b4e3e5
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.gd
@@ -0,0 +1,15 @@
+# GH-83468
+
+func non_static_func():
+ pass
+
+static var static_var:
+ set(_value):
+ var f := func ():
+ var g := func ():
+ non_static_func()
+ g.call()
+ f.call()
+
+func test():
+ pass
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out
new file mode 100644
index 0000000000..cdf3ab2aeb
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Cannot call non-static function "non_static_func()" from static function "@static_var_setter()".
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out
index f1e9ec34f2..81554ec707 100644
--- a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out
@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
-Cannot call non-static function "non_static()" for static variable initializer.
+Cannot call non-static function "non_static()" from a static variable initializer.