1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

GDScript: Allow boolean operators between any types

To make consistent with previous behavior. Mostly to be used in
conditions for `if` and `while`.
This commit is contained in:
George Marques
2023-03-10 16:01:17 -03:00
parent a1e3ef919c
commit d76b3f2a4c
3 changed files with 587 additions and 0 deletions

View File

@@ -4846,6 +4846,17 @@ GDScriptParser::DataType GDScriptAnalyzer::get_operation_type(Variant::Operator
}
GDScriptParser::DataType GDScriptAnalyzer::get_operation_type(Variant::Operator p_operation, const GDScriptParser::DataType &p_a, const GDScriptParser::DataType &p_b, bool &r_valid, const GDScriptParser::Node *p_source) {
if (p_operation == Variant::OP_AND || p_operation == Variant::OP_OR) {
// Those work for any type of argument and always return a boolean.
// They don't use the Variant operator since they have short-circuit semantics.
r_valid = true;
GDScriptParser::DataType result;
result.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
result.kind = GDScriptParser::DataType::BUILTIN;
result.builtin_type = Variant::BOOL;
return result;
}
Variant::Type a_type = p_a.builtin_type;
Variant::Type b_type = p_b.builtin_type;