From 7f37e2987a18cb29a206694104194c7adcd5e439 Mon Sep 17 00:00:00 2001 From: Mariano Suligoy Date: Sat, 14 Aug 2021 10:37:59 -0300 Subject: When analyzing GdScript sources, consider Enums as Dictionaries. Fixes #45558 --- modules/gdscript/gdscript_analyzer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index ab37e54cf1..5e5316f69a 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2351,7 +2351,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); -- cgit v1.2.3 From 70c5feb32c0c4cd8c6f6dd2d00f5187f1a57e331 Mon Sep 17 00:00:00 2001 From: Mariano Suligoy Date: Sun, 15 Aug 2021 16:25:47 -0300 Subject: Accept non unnamed enums as valid values for enums. Fixes #49357 --- modules/gdscript/gdscript_analyzer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 5e5316f69a..fe6d1a9240 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3499,6 +3499,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; -- cgit v1.2.3 From 62077086076fb99fb7fe014522c44ae83f87dc4d Mon Sep 17 00:00:00 2001 From: Mariano Suligoy Date: Tue, 17 Aug 2021 21:17:01 -0300 Subject: GdScript: Use reduced constant expression result when doing binary operations. Fixes #50293 --- modules/gdscript/gdscript_analyzer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index fe6d1a9240..c9b20463f6 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1717,11 +1717,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()) { -- cgit v1.2.3