GDScript assert message parsing bug fixed

Fix: #43540
This commit is contained in:
Thakee Nathees 2020-12-27 11:27:50 +05:30
parent 7d972b8c67
commit ebade0e454
3 changed files with 8 additions and 8 deletions

View file

@ -1215,7 +1215,10 @@ void GDScriptAnalyzer::resolve_constant(GDScriptParser::ConstantNode *p_constant
void GDScriptAnalyzer::resolve_assert(GDScriptParser::AssertNode *p_assert) { void GDScriptAnalyzer::resolve_assert(GDScriptParser::AssertNode *p_assert) {
reduce_expression(p_assert->condition); reduce_expression(p_assert->condition);
if (p_assert->message != nullptr) { if (p_assert->message != nullptr) {
reduce_literal(p_assert->message); reduce_expression(p_assert->message);
if (!p_assert->message->is_constant || p_assert->message->reduced_value.get_type() != Variant::STRING) {
push_error(R"(Expected constant string for assert error message.)", p_assert->message);
}
} }
p_assert->set_datatype(p_assert->condition->get_datatype()); p_assert->set_datatype(p_assert->condition->get_datatype());

View file

@ -1501,12 +1501,9 @@ GDScriptParser::AssertNode *GDScriptParser::parse_assert() {
if (match(GDScriptTokenizer::Token::COMMA)) { if (match(GDScriptTokenizer::Token::COMMA)) {
// Error message. // Error message.
if (consume(GDScriptTokenizer::Token::LITERAL, R"(Expected error message for assert after ",".)")) { assert->message = parse_expression(false);
assert->message = parse_literal(); if (assert->message == nullptr) {
if (assert->message->value.get_type() != Variant::STRING) { push_error(R"(Expected error message for assert after ",".)");
push_error(R"(Expected string for assert error message.)");
}
} else {
return nullptr; return nullptr;
} }
} }

View file

@ -286,7 +286,7 @@ public:
struct AssertNode : public Node { struct AssertNode : public Node {
ExpressionNode *condition = nullptr; ExpressionNode *condition = nullptr;
LiteralNode *message = nullptr; ExpressionNode *message = nullptr;
AssertNode() { AssertNode() {
type = ASSERT; type = ASSERT;