You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +00:00
Merge pull request #62760 from cdemirer/fix-annotation-initializer-conflict
Fix priority of annotated type vs initializer type
This commit is contained in:
@@ -655,43 +655,43 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
|
|||||||
} else {
|
} else {
|
||||||
ERR_PRINT("Parser bug (please report): tried to assign unset node without an identifier.");
|
ERR_PRINT("Parser bug (please report): tried to assign unset node without an identifier.");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (member.variable->datatype_specifier != nullptr) {
|
|
||||||
datatype = specified_type;
|
|
||||||
|
|
||||||
if (member.variable->initializer != nullptr) {
|
if (member.variable->datatype_specifier != nullptr) {
|
||||||
if (!is_type_compatible(datatype, member.variable->initializer->get_datatype(), true, member.variable->initializer)) {
|
datatype = specified_type;
|
||||||
// Try reverse test since it can be a masked subtype.
|
|
||||||
if (!is_type_compatible(member.variable->initializer->get_datatype(), datatype, true, member.variable->initializer)) {
|
if (member.variable->initializer != nullptr) {
|
||||||
push_error(vformat(R"(Value of type "%s" cannot be assigned to a variable of type "%s".)", member.variable->initializer->get_datatype().to_string(), datatype.to_string()), member.variable->initializer);
|
if (!is_type_compatible(datatype, member.variable->initializer->get_datatype(), true, member.variable->initializer)) {
|
||||||
} else {
|
// Try reverse test since it can be a masked subtype.
|
||||||
// TODO: Add warning.
|
if (!is_type_compatible(member.variable->initializer->get_datatype(), datatype, true, member.variable->initializer)) {
|
||||||
mark_node_unsafe(member.variable->initializer);
|
push_error(vformat(R"(Value of type "%s" cannot be assigned to a variable of type "%s".)", member.variable->initializer->get_datatype().to_string(), datatype.to_string()), member.variable->initializer);
|
||||||
member.variable->use_conversion_assign = true;
|
} else {
|
||||||
}
|
// TODO: Add warning.
|
||||||
} else if (datatype.builtin_type == Variant::INT && member.variable->initializer->get_datatype().builtin_type == Variant::FLOAT) {
|
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
parser->push_warning(member.variable->initializer, GDScriptWarning::NARROWING_CONVERSION);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if (member.variable->initializer->get_datatype().is_variant()) {
|
|
||||||
// TODO: Warn unsafe assign.
|
|
||||||
mark_node_unsafe(member.variable->initializer);
|
mark_node_unsafe(member.variable->initializer);
|
||||||
member.variable->use_conversion_assign = true;
|
member.variable->use_conversion_assign = true;
|
||||||
}
|
}
|
||||||
|
} else if (datatype.builtin_type == Variant::INT && member.variable->initializer->get_datatype().builtin_type == Variant::FLOAT) {
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
parser->push_warning(member.variable->initializer, GDScriptWarning::NARROWING_CONVERSION);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} else if (member.variable->infer_datatype) {
|
if (member.variable->initializer->get_datatype().is_variant()) {
|
||||||
if (member.variable->initializer == nullptr) {
|
// TODO: Warn unsafe assign.
|
||||||
push_error(vformat(R"(Cannot infer the type of "%s" variable because there's no default value.)", member.variable->identifier->name), member.variable->identifier);
|
mark_node_unsafe(member.variable->initializer);
|
||||||
} else if (!datatype.is_set() || datatype.has_no_type()) {
|
member.variable->use_conversion_assign = true;
|
||||||
push_error(vformat(R"(Cannot infer the type of "%s" variable because the initial value doesn't have a set type.)", member.variable->identifier->name), member.variable->initializer);
|
|
||||||
} else if (datatype.is_variant()) {
|
|
||||||
push_error(vformat(R"(Cannot infer the type of "%s" variable because the initial value is Variant. Use explicit "Variant" type if this is intended.)", member.variable->identifier->name), member.variable->initializer);
|
|
||||||
} else if (datatype.builtin_type == Variant::NIL) {
|
|
||||||
push_error(vformat(R"(Cannot infer the type of "%s" variable because the initial value is "null".)", member.variable->identifier->name), member.variable->initializer);
|
|
||||||
}
|
}
|
||||||
datatype.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
|
|
||||||
}
|
}
|
||||||
|
} else if (member.variable->infer_datatype) {
|
||||||
|
if (member.variable->initializer == nullptr) {
|
||||||
|
push_error(vformat(R"(Cannot infer the type of "%s" variable because there's no default value.)", member.variable->identifier->name), member.variable->identifier);
|
||||||
|
} else if (!datatype.is_set() || datatype.has_no_type()) {
|
||||||
|
push_error(vformat(R"(Cannot infer the type of "%s" variable because the initial value doesn't have a set type.)", member.variable->identifier->name), member.variable->initializer);
|
||||||
|
} else if (datatype.is_variant()) {
|
||||||
|
push_error(vformat(R"(Cannot infer the type of "%s" variable because the initial value is Variant. Use explicit "Variant" type if this is intended.)", member.variable->identifier->name), member.variable->initializer);
|
||||||
|
} else if (datatype.builtin_type == Variant::NIL) {
|
||||||
|
push_error(vformat(R"(Cannot infer the type of "%s" variable because the initial value is "null".)", member.variable->identifier->name), member.variable->initializer);
|
||||||
|
}
|
||||||
|
datatype.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
|
||||||
}
|
}
|
||||||
|
|
||||||
datatype.is_constant = false;
|
datatype.is_constant = false;
|
||||||
|
|||||||
@@ -2040,7 +2040,10 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &
|
|||||||
return true;
|
return true;
|
||||||
case GDScriptParser::ClassNode::Member::VARIABLE:
|
case GDScriptParser::ClassNode::Member::VARIABLE:
|
||||||
if (!is_static) {
|
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;
|
const GDScriptParser::ExpressionNode *init = member.variable->initializer;
|
||||||
if (init->is_constant) {
|
if (init->is_constant) {
|
||||||
r_type.value = init->reduced_value;
|
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();
|
r_type.type = init->get_datatype();
|
||||||
return true;
|
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.
|
// TODO: Check assignments in constructor.
|
||||||
|
|||||||
Reference in New Issue
Block a user