Merge pull request #62760 from cdemirer/fix-annotation-initializer-conflict

Fix priority of annotated type vs initializer type
This commit is contained in:
Rémi Verschelde 2022-07-06 15:47:56 +02:00 committed by GitHub
commit 4873886830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 34 deletions

View file

@ -655,7 +655,8 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
} else {
ERR_PRINT("Parser bug (please report): tried to assign unset node without an identifier.");
}
} else {
}
if (member.variable->datatype_specifier != nullptr) {
datatype = specified_type;
@ -692,7 +693,6 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
}
datatype.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
}
}
datatype.is_constant = false;
member.variable->set_datatype(datatype);

View file

@ -2040,7 +2040,10 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &
return true;
case GDScriptParser::ClassNode::Member::VARIABLE:
if (!is_static) {
if (member.variable->initializer) {
if (member.variable->get_datatype().is_set() && !member.variable->get_datatype().is_variant()) {
r_type.type = member.variable->get_datatype();
return true;
} else if (member.variable->initializer) {
const GDScriptParser::ExpressionNode *init = member.variable->initializer;
if (init->is_constant) {
r_type.value = init->reduced_value;
@ -2062,9 +2065,6 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &
r_type.type = init->get_datatype();
return true;
}
} else if (member.variable->get_datatype().is_set() && !member.variable->get_datatype().is_variant()) {
r_type.type = member.variable->get_datatype();
return true;
}
}
// TODO: Check assignments in constructor.