Browse Source

Merge pull request #53726 from briansemrau/gd-outer-class

GDScript 2.0: Access outer scope classes
George Marques 3 years ago
parent
commit
bf322bacdd

+ 5 - 0
modules/gdscript/gdscript_analyzer.cpp

@@ -2683,6 +2683,11 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
 						p_identifier->is_constant = false;
 						p_identifier->is_constant = false;
 						return;
 						return;
 					} break;
 					} break;
+					case GDScriptParser::ClassNode::Member::CLASS: {
+						resolve_class_interface(member.m_class);
+						p_identifier->set_datatype(member.m_class->get_datatype());
+						return;
+					} break;
 					default:
 					default:
 						break;
 						break;
 				}
 				}

+ 19 - 0
modules/gdscript/tests/scripts/analyzer/features/class_from_parent.gd

@@ -0,0 +1,19 @@
+class A:
+    var x = 3
+
+class B:
+    var x = 4
+
+class C:
+    var x = 5
+
+class Test:
+    var a = A.new()
+    var b: B = B.new()
+    var c := C.new()
+
+func test():
+    var test_instance := Test.new()
+    prints(test_instance.a.x)
+    prints(test_instance.b.x)
+    prints(test_instance.c.x)

+ 4 - 0
modules/gdscript/tests/scripts/analyzer/features/class_from_parent.out

@@ -0,0 +1,4 @@
+GDTEST_OK
+3
+4
+5