You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Merge pull request #30289 from bojidar-bg/29586-class-name-constant
Fix inheriting from class_name messing up constants
This commit is contained in:
@@ -826,11 +826,12 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check parents for the constant
|
// Check parents for the constant
|
||||||
if (!bfn && cln->extends_file != StringName()) {
|
if (!bfn) {
|
||||||
Ref<GDScript> parent = ResourceLoader::load(cln->extends_file);
|
// Using current_class instead of cln here, since cln is const*
|
||||||
if (parent.is_valid() && parent->is_valid()) {
|
_determine_inheritance(current_class, false);
|
||||||
|
if (cln->base_type.has_type && cln->base_type.kind == DataType::GDSCRIPT && cln->base_type.script_type->is_valid()) {
|
||||||
Map<StringName, Variant> parent_constants;
|
Map<StringName, Variant> parent_constants;
|
||||||
parent->get_constants(&parent_constants);
|
current_class->base_type.script_type->get_constants(&parent_constants);
|
||||||
if (parent_constants.has(identifier)) {
|
if (parent_constants.has(identifier)) {
|
||||||
ConstantNode *constant = alloc_node<ConstantNode>();
|
ConstantNode *constant = alloc_node<ConstantNode>();
|
||||||
constant->value = parent_constants[identifier];
|
constant->value = parent_constants[identifier];
|
||||||
@@ -5150,9 +5151,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
|
void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive) {
|
||||||
|
|
||||||
if (p_class->extends_used) {
|
if (p_class->base_type.has_type) {
|
||||||
|
// Already determined
|
||||||
|
} else if (p_class->extends_used) {
|
||||||
//do inheritance
|
//do inheritance
|
||||||
String path = p_class->extends_file;
|
String path = p_class->extends_file;
|
||||||
|
|
||||||
@@ -5347,9 +5350,11 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
|
|||||||
p_class->base_type.native_type = "Reference";
|
p_class->base_type.native_type = "Reference";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_recursive) {
|
||||||
// Recursively determine subclasses
|
// Recursively determine subclasses
|
||||||
for (int i = 0; i < p_class->subclasses.size(); i++) {
|
for (int i = 0; i < p_class->subclasses.size(); i++) {
|
||||||
_determine_inheritance(p_class->subclasses[i]);
|
_determine_inheritance(p_class->subclasses[i], p_recursive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -599,7 +599,7 @@ private:
|
|||||||
void _parse_class(ClassNode *p_class);
|
void _parse_class(ClassNode *p_class);
|
||||||
bool _end_statement();
|
bool _end_statement();
|
||||||
|
|
||||||
void _determine_inheritance(ClassNode *p_class);
|
void _determine_inheritance(ClassNode *p_class, bool p_recursive = true);
|
||||||
bool _parse_type(DataType &r_type, bool p_can_be_void = false);
|
bool _parse_type(DataType &r_type, bool p_can_be_void = false);
|
||||||
DataType _resolve_type(const DataType &p_source, int p_line);
|
DataType _resolve_type(const DataType &p_source, int p_line);
|
||||||
DataType _type_from_variant(const Variant &p_value) const;
|
DataType _type_from_variant(const Variant &p_value) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user