From 3f451c59c99a50230d1136dc12c02b5a7e934ccb Mon Sep 17 00:00:00 2001 From: rune-scape Date: Sat, 22 Feb 2025 23:28:10 -0800 Subject: [PATCH] GDScript: Fix error on operator `"member" in Class` --- modules/gdscript/gdscript_analyzer.cpp | 7 +++++++ .../analyzer/features/operator_constant_string_in_class.gd | 6 ++++++ .../features/operator_constant_string_in_class.out | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.out diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 60109efc4d5..dc53415f940 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3059,6 +3059,13 @@ void GDScriptAnalyzer::reduce_binary_op(GDScriptParser::BinaryOpNode *p_binary_o } #endif + bool lhs_is_stringy = left_type.kind == GDScriptParser::DataType::BUILTIN && (left_type.builtin_type == Variant::STRING || left_type.builtin_type == Variant::STRING_NAME); + bool rhs_is_meta_class = right_type.kind == GDScriptParser::DataType::CLASS && right_type.is_meta_type; + if (lhs_is_stringy && p_binary_op->variant_op == Variant::OP_IN && rhs_is_meta_class) { + // TODO: Some script members presence could be determined here. + return; + } + if (p_binary_op->left_operand->is_constant && p_binary_op->right_operand->is_constant) { p_binary_op->is_constant = true; if (p_binary_op->variant_op < Variant::OP_MAX) { diff --git a/modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.gd b/modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.gd new file mode 100644 index 00000000000..8b26329bd39 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.gd @@ -0,0 +1,6 @@ +class MyClass: + static func my_static(): + print("my_static") + +func test(): + print("my_static" in MyClass) diff --git a/modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.out b/modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.out new file mode 100644 index 00000000000..55482c2b52e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/operator_constant_string_in_class.out @@ -0,0 +1,2 @@ +GDTEST_OK +true