diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-09-30 18:35:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-30 18:35:49 +0200 |
commit | 7f8e50801e3a70f7df61632088a94a12020c1f3b (patch) | |
tree | 5beb2e8126a6b0d1930f1b3e0fea16ac45f0e2eb | |
parent | a201f30c7fb3c5c37dfb78bace64dc389c448014 (diff) | |
parent | 62077086076fb99fb7fe014522c44ae83f87dc4d (diff) |
Merge pull request #51818 from MarianoGnu/gdscript2-enum-fixes
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index aa62ad20ff..2485e9f432 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1867,11 +1867,19 @@ void GDScriptAnalyzer::reduce_binary_op(GDScriptParser::BinaryOpNode *p_binary_o GDScriptParser::DataType left_type; if (p_binary_op->left_operand) { - left_type = p_binary_op->left_operand->get_datatype(); + if (p_binary_op->left_operand->is_constant) { + left_type = type_from_variant(p_binary_op->left_operand->reduced_value, p_binary_op->left_operand); + } else { + left_type = p_binary_op->left_operand->get_datatype(); + } } GDScriptParser::DataType right_type; if (p_binary_op->right_operand) { - right_type = p_binary_op->right_operand->get_datatype(); + if (p_binary_op->right_operand->is_constant) { + right_type = type_from_variant(p_binary_op->right_operand->reduced_value, p_binary_op->right_operand); + } else { + right_type = p_binary_op->right_operand->get_datatype(); + } } if (!left_type.is_set() || !right_type.is_set()) { @@ -2508,7 +2516,10 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod result.enum_type = name; p_identifier->set_datatype(result); } else { - push_error(vformat(R"(Cannot find value "%s" in "%s".)", name, base.to_string()), p_identifier); + // Consider as a Dictionary + GDScriptParser::DataType dummy; + dummy.kind = GDScriptParser::DataType::VARIANT; + p_identifier->set_datatype(dummy); } } else { push_error(R"(Cannot get property from enum value.)", p_identifier); @@ -3681,6 +3692,11 @@ bool GDScriptAnalyzer::is_type_compatible(const GDScriptParser::DataType &p_targ if (p_source.kind == GDScriptParser::DataType::BUILTIN && p_source.builtin_type == Variant::INT) { return true; } + if (p_source.kind == GDScriptParser::DataType::ENUM) { + if (p_source.native_type == p_target.native_type) { + return true; + } + } if (p_source.kind == GDScriptParser::DataType::ENUM_VALUE) { if (p_source.native_type == p_target.native_type && p_target.enum_values.has(p_source.enum_type)) { return true; |