diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-09-15 16:43:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-15 16:43:38 +0200 |
commit | ed11d03b56d14f2868eaae041a42d1c4d4d425c1 (patch) | |
tree | e5bebdd166a858bc2b71c79602334ff5395510dc /modules/gdscript/gdscript_parser.cpp | |
parent | a5c299630d865ca61a1943c9ce38936f9ac18063 (diff) | |
parent | d49046938a22fc2fd75087bfdd68fc1f369e8a6c (diff) | |
download | redot-engine-ed11d03b56d14f2868eaae041a42d1c4d4d425c1.tar.gz |
Merge pull request #52705 from vnen/gdscript-error-unary-no-arg
GDScript: Show error on unary operators without argument
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 42c06d8161..c9ac055392 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2123,22 +2123,34 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_unary_operator(ExpressionN operation->operation = UnaryOpNode::OP_NEGATIVE; operation->variant_op = Variant::OP_NEGATE; operation->operand = parse_precedence(PREC_SIGN, false); + if (operation->operand == nullptr) { + push_error(R"(Expected expression after "-" operator.)"); + } break; case GDScriptTokenizer::Token::PLUS: operation->operation = UnaryOpNode::OP_POSITIVE; operation->variant_op = Variant::OP_POSITIVE; operation->operand = parse_precedence(PREC_SIGN, false); + if (operation->operand == nullptr) { + push_error(R"(Expected expression after "+" operator.)"); + } break; case GDScriptTokenizer::Token::TILDE: operation->operation = UnaryOpNode::OP_COMPLEMENT; operation->variant_op = Variant::OP_BIT_NEGATE; operation->operand = parse_precedence(PREC_BIT_NOT, false); + if (operation->operand == nullptr) { + push_error(R"(Expected expression after "~" operator.)"); + } break; case GDScriptTokenizer::Token::NOT: case GDScriptTokenizer::Token::BANG: operation->operation = UnaryOpNode::OP_LOGIC_NOT; operation->variant_op = Variant::OP_NOT; operation->operand = parse_precedence(PREC_LOGIC_NOT, false); + if (operation->operand == nullptr) { + push_error(vformat(R"(Expected expression after "%s" operator.)", op_type == GDScriptTokenizer::Token::NOT ? "not" : "!")); + } break; default: return nullptr; // Unreachable. |