From 1bbb2b415997cceaf292c796c28de2761ad40960 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Sat, 17 Dec 2022 17:53:49 -0500 Subject: [PATCH] Fix outer class lookup --- modules/gdscript/gdscript_analyzer.cpp | 2 +- .../scripts/analyzer/errors/outer_class_lookup.gd | 12 ++++++++++++ .../scripts/analyzer/errors/outer_class_lookup.out | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.out diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 3bbe71fb900..5af0b22d441 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3167,7 +3167,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod // TODO: Allow outer static functions. if (base_class->outer != nullptr) { List script_classes; - get_class_node_current_scope_classes(parser->current_class, &script_classes); + get_class_node_current_scope_classes(base_class->outer, &script_classes); for (GDScriptParser::ClassNode *script_class : script_classes) { if (script_class->has_member(name)) { resolve_class_member(script_class, name, p_identifier); diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd new file mode 100644 index 00000000000..65c0d9dabcc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd @@ -0,0 +1,12 @@ +class A: + class B: + func test(): + print(A.B.D) + +class C: + class D: + pass + +func test(): + var inst = A.B.new() + inst.test() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.out b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.out new file mode 100644 index 00000000000..6baed366f60 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot find member "D" in base "B".