From fb45cab133103de4f641cc72a553a28463bed7fd Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Fri, 11 Aug 2023 11:22:01 +0300 Subject: [PATCH] GDScript: Fix "Identifier not found" error when accessing inner class from inside --- modules/gdscript/gdscript_analyzer.cpp | 3 +++ .../inner_class_access_from_inside.gd | 21 +++++++++++++++++++ .../inner_class_access_from_inside.out | 5 +++++ 3 files changed, 29 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.out diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index cb049136201..ad4528747b7 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3469,6 +3469,9 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod for (GDScriptParser::ClassNode *script_class : script_classes) { if (p_base == nullptr && script_class->identifier && script_class->identifier->name == name) { reduce_identifier_from_base_set_class(p_identifier, script_class->get_datatype()); + if (script_class->outer != nullptr) { + p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CLASS; + } return; } diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.gd b/modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.gd new file mode 100644 index 00000000000..51c589b8e09 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.gd @@ -0,0 +1,21 @@ +# GH-80508 + +class A: + func a(): + return A.new() + func b(): + return B.new() + +class B: + func a(): + return A.new() + func b(): + return B.new() + +func test(): + var a := A.new() + var b := B.new() + print(a.a() is A) + print(a.b() is B) + print(b.a() is A) + print(b.b() is B) diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.out b/modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.out new file mode 100644 index 00000000000..f9783e43629 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/inner_class_access_from_inside.out @@ -0,0 +1,5 @@ +GDTEST_OK +true +true +true +true