Merge pull request #70859 from vonagam/fix-preload-native-type

GDScript: Fix wrong native type for preloaded class
This commit is contained in:
Rémi Verschelde 2023-01-03 23:22:23 +01:00
commit 8203e09330
No known key found for this signature in database
GPG Key ID: C3336907360768E1
4 changed files with 22 additions and 2 deletions

View File

@ -3998,10 +3998,8 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_variant(const Variant &p_va
scr = obj->get_script(); scr = obj->get_script();
} }
if (scr.is_valid()) { if (scr.is_valid()) {
result.script_path = scr->get_path();
Ref<GDScript> gds = scr; Ref<GDScript> gds = scr;
if (gds.is_valid()) { if (gds.is_valid()) {
result.kind = GDScriptParser::DataType::CLASS;
// This might be an inner class, so we want to get the parser for the root. // This might be an inner class, so we want to get the parser for the root.
// But still get the inner class from that tree. // But still get the inner class from that tree.
String script_path = gds->get_script_path(); String script_path = gds->get_script_path();
@ -4027,11 +4025,14 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_variant(const Variant &p_va
return error_type; return error_type;
} }
result.kind = GDScriptParser::DataType::CLASS;
result.native_type = found->get_datatype().native_type;
result.class_type = found; result.class_type = found;
result.script_path = ref->get_parser()->script_path; result.script_path = ref->get_parser()->script_path;
} else { } else {
result.kind = GDScriptParser::DataType::SCRIPT; result.kind = GDScriptParser::DataType::SCRIPT;
result.native_type = scr->get_instance_base_type(); result.native_type = scr->get_instance_base_type();
result.script_path = scr->get_path();
} }
result.script_type = scr; result.script_type = scr;
} else { } else {

View File

@ -0,0 +1,15 @@
const Preloaded := preload( 'preload_script_native_type.notest.gd' )
func test() -> void:
var inferred := Preloaded.new()
var inferred_owner := inferred.owner
var typed: Preloaded
typed = Preloaded.new()
var typed_owner := typed.owner
print(typed_owner == inferred_owner)
inferred.free()
typed.free()
print('ok')

View File

@ -0,0 +1,3 @@
GDTEST_OK
true
ok