From 701335e845166acb2a386778a70476ee57f33919 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 18 Apr 2015 17:55:04 -0300 Subject: -Throw error if setter and getter reference their member variable with self. , fixes #1685 --- modules/gdscript/gd_compiler.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'modules/gdscript') 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::Element *MI = codegen.script->member_indices.find(static_cast(on->arguments[1])->name); + if (MI && MI->get().getter==codegen.function_node->name) { + String n = static_cast(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(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(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX || static_cast(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX_NAMED)) { //SET (chained) MODE!! + +#ifdef DEBUG_ENABLED + if (static_cast(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX_NAMED) { + const GDParser::OperatorNode* inon = static_cast(on->arguments[0]); + + + if (inon->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { + + const Map::Element *MI = codegen.script->member_indices.find(static_cast(inon->arguments[1])->name); + if (MI && MI->get().setter==codegen.function_node->name) { + String n = static_cast(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(on->arguments[0]); -- cgit v1.2.3