Browse Source

GDScript: Fix setting type of operator return value

Also write type adjust when needed for binary operators.
George Marques 4 years ago
parent
commit
b5f1e88b2e

+ 1 - 0
modules/gdscript/gdscript_analyzer.cpp

@@ -3446,6 +3446,7 @@ GDScriptParser::DataType GDScriptAnalyzer::get_operation_type(Variant::Operator
 	}
 	}
 
 
 	r_valid = true;
 	r_valid = true;
+	result.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
 
 
 	result.kind = GDScriptParser::DataType::BUILTIN;
 	result.kind = GDScriptParser::DataType::BUILTIN;
 	result.builtin_type = Variant::get_operator_return_type(p_operation, a_type, b_type);
 	result.builtin_type = Variant::get_operator_return_type(p_operation, a_type, b_type);

+ 8 - 0
modules/gdscript/gdscript_byte_codegen.cpp

@@ -554,6 +554,14 @@ void GDScriptByteCodeGenerator::write_unary_operator(const Address &p_target, Va
 
 
 void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, Variant::Operator p_operator, const Address &p_left_operand, const Address &p_right_operand) {
 void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, Variant::Operator p_operator, const Address &p_left_operand, const Address &p_right_operand) {
 	if (HAS_BUILTIN_TYPE(p_left_operand) && HAS_BUILTIN_TYPE(p_right_operand)) {
 	if (HAS_BUILTIN_TYPE(p_left_operand) && HAS_BUILTIN_TYPE(p_right_operand)) {
+		if (p_target.mode == Address::TEMPORARY) {
+			Variant::Type result_type = Variant::get_operator_return_type(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type);
+			Variant::Type temp_type = temporaries[p_target.address].type;
+			if (result_type != temp_type) {
+				write_type_adjust(p_target, result_type);
+			}
+		}
+
 		// Gather specific operator.
 		// Gather specific operator.
 		Variant::ValidatedOperatorEvaluator op_func = Variant::get_validated_operator_evaluator(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type);
 		Variant::ValidatedOperatorEvaluator op_func = Variant::get_validated_operator_evaluator(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type);