summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBojidar Marinov <bojidar.marinov.bg@gmail.com>2016-12-29 12:31:19 +0200
committerBojidar Marinov <bojidar.marinov.bg@gmail.com>2016-12-29 12:31:19 +0200
commit0b077162a32d37b81c302ab26523efda05de3913 (patch)
tree892330240b4b3a89625524f43af9fc6ea3c567cc
parentc798ff15510997fdbe6848687804f5e2cb17eefb (diff)
Disallow assignment to constants and expressions
Fixes #6221, fixes #6824
-rw-r--r--modules/gdscript/gd_parser.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 1f2b7291e5..2b5cd9c274 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -1478,6 +1478,15 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
return op;
}
+ if (op->arguments[0]->type==Node::TYPE_OPERATOR) {
+ OperatorNode *on = static_cast<OperatorNode*>(op->arguments[0]);
+ if (on->op != OperatorNode::OP_INDEX && on->op != OperatorNode::OP_INDEX_NAMED) {
+ _set_error("Can't assign to an expression",tokenizer->get_token_line()-1);
+ error_line=op->line;
+ return op;
+ }
+ }
+
} break;
default: { break; }
}
@@ -2014,7 +2023,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
} break;
default: {
- Node *expression = _parse_and_reduce_expression(p_block,p_static,false,true);
+ Node *expression = _parse_and_reduce_expression(p_block,p_static,true,true);
if (!expression) {
if (_recover_from_completion()) {
break;