Browse Source

GDScript: Fix setting native type with script inheritance

Sometimes the inheritance tree is compiled out of order and the base
don't have yet a native type set. This is now changed to not rely on the
base script but use the native type set in the datatype, which is
already resolved by the analyzer.
George Marques 2 years ago
parent
commit
d076c76551
1 changed files with 7 additions and 6 deletions
  1. 7 6
      modules/gdscript/gdscript_compiler.cpp

+ 7 - 6
modules/gdscript/gdscript_compiler.cpp

@@ -2265,13 +2265,15 @@ Error GDScriptCompiler::_populate_class_members(GDScript *p_script, const GDScri
 
 
 	GDScriptDataType base_type = _gdtype_from_datatype(p_class->base_type, p_script);
 	GDScriptDataType base_type = _gdtype_from_datatype(p_class->base_type, p_script);
 
 
+	int native_idx = GDScriptLanguage::get_singleton()->get_global_map()[base_type.native_type];
+	p_script->native = GDScriptLanguage::get_singleton()->get_global_array()[native_idx];
+	ERR_FAIL_COND_V(p_script->native.is_null(), ERR_BUG);
+
 	// Inheritance
 	// Inheritance
 	switch (base_type.kind) {
 	switch (base_type.kind) {
-		case GDScriptDataType::NATIVE: {
-			int native_idx = GDScriptLanguage::get_singleton()->get_global_map()[base_type.native_type];
-			p_script->native = GDScriptLanguage::get_singleton()->get_global_array()[native_idx];
-			ERR_FAIL_COND_V(p_script->native.is_null(), ERR_BUG);
-		} break;
+		case GDScriptDataType::NATIVE:
+			// Nothing more to do.
+			break;
 		case GDScriptDataType::GDSCRIPT: {
 		case GDScriptDataType::GDSCRIPT: {
 			Ref<GDScript> base = Ref<GDScript>(base_type.script_type);
 			Ref<GDScript> base = Ref<GDScript>(base_type.script_type);
 			if (base.is_null()) {
 			if (base.is_null()) {
@@ -2303,7 +2305,6 @@ Error GDScriptCompiler::_populate_class_members(GDScript *p_script, const GDScri
 			p_script->base = base;
 			p_script->base = base;
 			p_script->_base = base.ptr();
 			p_script->_base = base.ptr();
 			p_script->member_indices = base->member_indices;
 			p_script->member_indices = base->member_indices;
-			p_script->native = base->native;
 		} break;
 		} break;
 		default: {
 		default: {
 			_set_error("Parser bug: invalid inheritance.", nullptr);
 			_set_error("Parser bug: invalid inheritance.", nullptr);