mirror of
https://github.com/godotengine/godot.git
synced 2024-11-23 04:33:29 +00:00
-Throw error if setter and getter reference their member variable with self. , fixes #1685
This commit is contained in:
parent
389d6ca0c7
commit
701335e845
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user