From 7fc814f69783ee5d3bde040bdbb057730e50bc30 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Sat, 17 Dec 2022 16:19:18 -0500 Subject: [PATCH] Fix external enums not assignable as constants - Add external enums test - Rename external inner class test - Clean up `GDScriptAnalyzer::reduce_identifier_from_base` class behavior --- modules/gdscript/gdscript_analyzer.cpp | 10 +++++++++- .../analyzer/features/external_enum_as_constant.gd | 6 ++++++ .../analyzer/features/external_enum_as_constant.out | 3 +++ .../external_enum_as_constant_external.notest.gd | 4 ++++ ...signment.gd => external_inner_class_as_constant.gd} | 2 +- ...gnment.out => external_inner_class_as_constant.out} | 0 ...xternal_inner_class_as_constant_external.notest.gd} | 0 7 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd rename modules/gdscript/tests/scripts/analyzer/features/{inner_class_constant_assignment.gd => external_inner_class_as_constant.gd} (68%) rename modules/gdscript/tests/scripts/analyzer/features/{inner_class_constant_assignment.out => external_inner_class_as_constant.out} (100%) rename modules/gdscript/tests/scripts/analyzer/features/{inner_class_constant_assignment_external.notest.gd => external_inner_class_as_constant_external.notest.gd} (100%) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 3bbe71fb900..efc74a07026 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3137,6 +3137,12 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod p_identifier->reduced_value = member.enum_value.value; p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT; break; + case GDScriptParser::ClassNode::Member::ENUM: + if (p_base != nullptr && p_base->is_constant) { + p_identifier->is_constant = true; + p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT; + } + break; case GDScriptParser::ClassNode::Member::VARIABLE: p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_VARIABLE; p_identifier->variable_source = member.variable; @@ -3150,12 +3156,14 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod break; case GDScriptParser::ClassNode::Member::CLASS: if (p_base != nullptr && p_base->is_constant) { + p_identifier->is_constant = true; + p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT; + Error err = OK; GDScript *scr = GDScriptCache::get_full_script(base.script_path, err).ptr(); ERR_FAIL_COND_MSG(err != OK, "Error while getting subscript full script."); scr = scr->find_class(p_identifier->get_datatype().class_type->fqcn); p_identifier->reduced_value = scr; - p_identifier->is_constant = true; } break; default: diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd new file mode 100644 index 00000000000..757744b6f1c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd @@ -0,0 +1,6 @@ +const External = preload("external_enum_as_constant_external.notest.gd") +const MyEnum = External.MyEnum + +func test(): + print(MyEnum.WAITING == 0) + print(MyEnum.GODOT == 1) diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.out b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.out new file mode 100644 index 00000000000..9d111a83225 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.out @@ -0,0 +1,3 @@ +GDTEST_OK +true +true diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd new file mode 100644 index 00000000000..7c090844d08 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd @@ -0,0 +1,4 @@ +enum MyEnum { + WAITING, + GODOT +} diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.gd b/modules/gdscript/tests/scripts/analyzer/features/external_inner_class_as_constant.gd similarity index 68% rename from modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.gd rename to modules/gdscript/tests/scripts/analyzer/features/external_inner_class_as_constant.gd index ed5fb18b73e..18dca109fb3 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/external_inner_class_as_constant.gd @@ -1,4 +1,4 @@ -const External = preload("inner_class_constant_assignment_external.notest.gd") +const External = preload("external_inner_class_as_constant_external.notest.gd") const ExternalInnerClass = External.InnerClass func test(): diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.out b/modules/gdscript/tests/scripts/analyzer/features/external_inner_class_as_constant.out similarity index 100% rename from modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.out rename to modules/gdscript/tests/scripts/analyzer/features/external_inner_class_as_constant.out diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment_external.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_inner_class_as_constant_external.notest.gd similarity index 100% rename from modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment_external.notest.gd rename to modules/gdscript/tests/scripts/analyzer/features/external_inner_class_as_constant_external.notest.gd