Browse Source

Merge pull request #64046 from AntonioDell/bugfix/63715-infer-preloaded-const-types

Rémi Verschelde 3 years ago
parent
commit
7801ad0531

+ 1 - 1
modules/gdscript/gdscript_analyzer.cpp

@@ -3238,12 +3238,12 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri
 			Variant value = p_subscript->base->reduced_value.get_named(p_subscript->attribute->name, valid);
 			if (!valid) {
 				push_error(vformat(R"(Cannot get member "%s" from "%s".)", p_subscript->attribute->name, p_subscript->base->reduced_value), p_subscript->index);
+				result_type.kind = GDScriptParser::DataType::VARIANT;
 			} else {
 				p_subscript->is_constant = true;
 				p_subscript->reduced_value = value;
 				result_type = type_from_variant(value, p_subscript);
 			}
-			result_type.kind = GDScriptParser::DataType::VARIANT;
 		} else {
 			GDScriptParser::DataType base_type = p_subscript->base->get_datatype();
 

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd

@@ -1,3 +1,5 @@
+const A := 42
+
 func test():
 	pass
 

+ 6 - 0
modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd

@@ -0,0 +1,6 @@
+const Constants = preload("gdscript_to_preload.gd")
+
+func test():
+	var a := Constants.A
+	print(a)
+

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+42