GDScript: Fix use of conversion assign for variant values
This commit is contained in:
parent
91713ced81
commit
04d0e851ea
3 changed files with 14 additions and 2 deletions
|
@ -2110,14 +2110,14 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig
|
||||||
|
|
||||||
bool compatible = true;
|
bool compatible = true;
|
||||||
GDScriptParser::DataType op_type = assigned_value_type;
|
GDScriptParser::DataType op_type = assigned_value_type;
|
||||||
if (p_assignment->operation != GDScriptParser::AssignmentNode::OP_NONE) {
|
if (p_assignment->operation != GDScriptParser::AssignmentNode::OP_NONE && !op_type.is_variant()) {
|
||||||
op_type = get_operation_type(p_assignment->variant_op, assignee_type, assigned_value_type, compatible, p_assignment->assigned_value);
|
op_type = get_operation_type(p_assignment->variant_op, assignee_type, assigned_value_type, compatible, p_assignment->assigned_value);
|
||||||
}
|
}
|
||||||
p_assignment->set_datatype(op_type);
|
p_assignment->set_datatype(op_type);
|
||||||
|
|
||||||
// If Assignee is a variant, then you can assign anything
|
// If Assignee is a variant, then you can assign anything
|
||||||
// When the assigned value has a known type, further checks are possible.
|
// When the assigned value has a known type, further checks are possible.
|
||||||
if (assignee_type.is_hard_type() && !assignee_type.is_variant() && op_type.is_hard_type()) {
|
if (assignee_type.is_hard_type() && !assignee_type.is_variant() && op_type.is_hard_type() && !op_type.is_variant()) {
|
||||||
if (compatible) {
|
if (compatible) {
|
||||||
compatible = is_type_compatible(assignee_type, op_type, true, p_assignment->assigned_value);
|
compatible = is_type_compatible(assignee_type, op_type, true, p_assignment->assigned_value);
|
||||||
if (!compatible) {
|
if (!compatible) {
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# https://github.com/godotengine/godot/issues/71172
|
||||||
|
|
||||||
|
func test():
|
||||||
|
@warning_ignore(narrowing_conversion)
|
||||||
|
var foo: int = 0.0
|
||||||
|
print(typeof(foo) == TYPE_INT)
|
||||||
|
var dict : Dictionary = {"a":0.0}
|
||||||
|
foo = dict.get("a")
|
||||||
|
print(typeof(foo) == TYPE_INT)
|
|
@ -0,0 +1,3 @@
|
||||||
|
GDTEST_OK
|
||||||
|
true
|
||||||
|
true
|
Loading…
Reference in a new issue