diff options
author | George Marques <george@gmarqu.es> | 2023-03-10 16:01:17 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2023-03-10 16:01:17 -0300 |
commit | d76b3f2a4c7f2e59a0e0592cac8877f382070f14 (patch) | |
tree | 4125b812909e8df55d7cac9575e4c6314d8520ae /modules/gdscript/gdscript_analyzer.cpp | |
parent | a1e3ef919c14424e047f5e0e4d2569b4e4ca33d9 (diff) | |
download | redot-engine-d76b3f2a4c7f2e59a0e0592cac8877f382070f14.tar.gz |
GDScript: Allow boolean operators between any types
To make consistent with previous behavior. Mostly to be used in
conditions for `if` and `while`.
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 38d5ae6b77..831f9a3efd 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -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; |