Skip to content

Commit

Permalink
Merge pull request godotengine#44719 from ThakeeNathees/assert-argume…
Browse files Browse the repository at this point in the history
…nt-bug-fixed

GDScript assert message parsing bug fixed
  • Loading branch information
akien-mga authored Jan 11, 2021
2 parents a202158 + ebade0e commit 8363c44
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 4 additions & 1 deletion modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,10 @@ void GDScriptAnalyzer::resolve_constant(GDScriptParser::ConstantNode *p_constant
void GDScriptAnalyzer::resolve_assert(GDScriptParser::AssertNode *p_assert) {
reduce_expression(p_assert->condition);
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());
Expand Down
9 changes: 3 additions & 6 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,12 +1503,9 @@ GDScriptParser::AssertNode *GDScriptParser::parse_assert() {

if (match(GDScriptTokenizer::Token::COMMA)) {
// Error message.
if (consume(GDScriptTokenizer::Token::LITERAL, R"(Expected error message for assert after ",".)")) {
assert->message = parse_literal();
if (assert->message->value.get_type() != Variant::STRING) {
push_error(R"(Expected string for assert error message.)");
}
} else {
assert->message = parse_expression(false);
if (assert->message == nullptr) {
push_error(R"(Expected error message for assert after ",".)");
return nullptr;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class GDScriptParser {

struct AssertNode : public Node {
ExpressionNode *condition = nullptr;
LiteralNode *message = nullptr;
ExpressionNode *message = nullptr;

AssertNode() {
type = ASSERT;
Expand Down

0 comments on commit 8363c44

Please sign in to comment.