You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-21 14:57:09 +00:00
fix(gdscript): Infer type from preload const
When resolving the type of the attribute from the variant, the result_type.kind was overritten for no reason. It is assumed that this only needs to be done, if the variant value is not valid to have any kind here. Solves #63715
This commit is contained in:
@@ -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);
|
Variant value = p_subscript->base->reduced_value.get_named(p_subscript->attribute->name, valid);
|
||||||
if (!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);
|
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 {
|
} else {
|
||||||
p_subscript->is_constant = true;
|
p_subscript->is_constant = true;
|
||||||
p_subscript->reduced_value = value;
|
p_subscript->reduced_value = value;
|
||||||
result_type = type_from_variant(value, p_subscript);
|
result_type = type_from_variant(value, p_subscript);
|
||||||
}
|
}
|
||||||
result_type.kind = GDScriptParser::DataType::VARIANT;
|
|
||||||
} else {
|
} else {
|
||||||
GDScriptParser::DataType base_type = p_subscript->base->get_datatype();
|
GDScriptParser::DataType base_type = p_subscript->base->get_datatype();
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const A := 42
|
||||||
|
|
||||||
func test():
|
func test():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const Constants = preload("gdscript_to_preload.gd")
|
||||||
|
|
||||||
|
func test():
|
||||||
|
var a := Constants.A
|
||||||
|
print(a)
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GDTEST_OK
|
||||||
|
42
|
||||||
Reference in New Issue
Block a user