summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Scott <ascott.ca@gmail.com>2022-12-14 08:33:53 -0500
committerAdam Scott <ascott.ca@gmail.com>2022-12-17 12:03:03 -0500
commit2fefcf7329287c34ee9c5143ab96a7976d96a33e (patch)
treed01f06a3bfe8a99fd82efcae170d9354b3f9094d
parent8d52eea52b4914a26409823047fc2ffd82c294f0 (diff)
Fix inner class constant assignment
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp10
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.gd7
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment_external.notest.gd2
4 files changed, 21 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 7d14bcf3c4..3bbe71fb90 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -3148,6 +3148,16 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
case GDScriptParser::ClassNode::Member::FUNCTION:
p_identifier->set_datatype(make_callable_type(member.function->info));
break;
+ case GDScriptParser::ClassNode::Member::CLASS:
+ if (p_base != nullptr && p_base->is_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:
break; // Type already set.
}
diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.gd b/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.gd
new file mode 100644
index 0000000000..ed5fb18b73
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.gd
@@ -0,0 +1,7 @@
+const External = preload("inner_class_constant_assignment_external.notest.gd")
+const ExternalInnerClass = External.InnerClass
+
+func test():
+ var inst_external: ExternalInnerClass = ExternalInnerClass.new()
+ inst_external.x = 4.0
+ print(inst_external.x)
diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.out b/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.out
new file mode 100644
index 0000000000..15666c46ad
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment.out
@@ -0,0 +1,2 @@
+GDTEST_OK
+4
diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment_external.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment_external.notest.gd
new file mode 100644
index 0000000000..788c99d469
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/inner_class_constant_assignment_external.notest.gd
@@ -0,0 +1,2 @@
+class InnerClass:
+ var x: = 3.0