summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-04-18 17:55:04 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-04-18 17:55:04 -0300
commit701335e845166acb2a386778a70476ee57f33919 (patch)
tree09ef3ce4688c1bbf148d61d358c69870e8b6e07f /modules/gdscript
parent389d6ca0c7ad6d0609731b279f30df011c6bf40a (diff)
-Throw error if setter and getter reference their member variable with self. , fixes #1685
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gd_compiler.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp
index dbe5f28336..b405555ec6 100644
--- a/modules/gdscript/gd_compiler.cpp
+++ b/modules/gdscript/gd_compiler.cpp
@@ -559,7 +559,17 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
int index;
if (named) {
+#ifdef DEBUG_ENABLED
+ if (on->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) {
+ const Map<StringName,GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name);
+ if (MI && MI->get().getter==codegen.function_node->name) {
+ String n = static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name;
+ _set_error("Must use '"+n+"' instead of 'self."+n+"' in getter.",on);
+ return -1;
+ }
+ }
+#endif
index=codegen.get_name_map_pos(static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name);
} else {
@@ -703,6 +713,25 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
if (on->arguments[0]->type==GDParser::Node::TYPE_OPERATOR && (static_cast<GDParser::OperatorNode*>(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX || static_cast<GDParser::OperatorNode*>(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX_NAMED)) {
//SET (chained) MODE!!
+
+#ifdef DEBUG_ENABLED
+ if (static_cast<GDParser::OperatorNode*>(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX_NAMED) {
+ const GDParser::OperatorNode* inon = static_cast<GDParser::OperatorNode*>(on->arguments[0]);
+
+
+ if (inon->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) {
+
+ const Map<StringName,GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDParser::IdentifierNode*>(inon->arguments[1])->name);
+ if (MI && MI->get().setter==codegen.function_node->name) {
+ String n = static_cast<GDParser::IdentifierNode*>(inon->arguments[1])->name;
+ _set_error("Must use '"+n+"' instead of 'self."+n+"' in setter.",inon);
+ return -1;
+ }
+ }
+ }
+#endif
+
+
int slevel=p_stack_level;
GDParser::OperatorNode* op = static_cast<GDParser::OperatorNode*>(on->arguments[0]);