summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-09-30 18:35:49 +0200
committerGitHub <noreply@github.com>2021-09-30 18:35:49 +0200
commit7f8e50801e3a70f7df61632088a94a12020c1f3b (patch)
tree5beb2e8126a6b0d1930f1b3e0fea16ac45f0e2eb
parenta201f30c7fb3c5c37dfb78bace64dc389c448014 (diff)
parent62077086076fb99fb7fe014522c44ae83f87dc4d (diff)
Merge pull request #51818 from MarianoGnu/gdscript2-enum-fixes
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp22
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;