Merge pull request #70220 from adamscott/fix-external-enum

Fix external enums not assignable as constants
This commit is contained in:
Rémi Verschelde 2022-12-23 09:20:50 +01:00
commit edfa1e8665
No known key found for this signature in database
GPG Key ID: C3336907360768E1
7 changed files with 23 additions and 2 deletions

View File

@ -3139,6 +3139,12 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
p_identifier->reduced_value = member.enum_value.value;
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT;
break;
case GDScriptParser::ClassNode::Member::ENUM:
if (p_base != nullptr && p_base->is_constant) {
p_identifier->is_constant = true;
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT;
}
break;
case GDScriptParser::ClassNode::Member::VARIABLE:
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_VARIABLE;
p_identifier->variable_source = member.variable;
@ -3152,12 +3158,14 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
break;
case GDScriptParser::ClassNode::Member::CLASS:
if (p_base != nullptr && p_base->is_constant) {
p_identifier->is_constant = true;
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT;
Error err = OK;
GDScript *scr = GDScriptCache::get_full_script(base.script_path, err).ptr();
ERR_FAIL_COND_MSG(err != OK, "Error while getting subscript full script.");
scr = scr->find_class(p_identifier->get_datatype().class_type->fqcn);
p_identifier->reduced_value = scr;
p_identifier->is_constant = true;
}
break;
default:

View File

@ -0,0 +1,6 @@
const External = preload("external_enum_as_constant_external.notest.gd")
const MyEnum = External.MyEnum
func test():
print(MyEnum.WAITING == 0)
print(MyEnum.GODOT == 1)

View File

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

View File

@ -0,0 +1,4 @@
enum MyEnum {
WAITING,
GODOT
}

View File

@ -1,4 +1,4 @@
const External = preload("inner_class_constant_assignment_external.notest.gd")
const External = preload("external_inner_class_as_constant_external.notest.gd")
const ExternalInnerClass = External.InnerClass
func test():