Fix #24895 (support for optional parameters in setters)

This commit is contained in:
Allan Daemon 2019-01-16 01:38:37 -02:00
parent 2c9536b655
commit 465842d8ea
2 changed files with 4 additions and 2 deletions

View file

@ -7410,7 +7410,8 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
found_setter = true;
FunctionNode *setter = p_class->functions[j];
if (setter->arguments.size() != 1) {
if (setter->get_required_argument_count() != 1 &&
!(setter->get_required_argument_count() == 0 && setter->default_values.size() > 0)) {
_set_error("Setter function needs to receive exactly 1 argument. See '" + setter->name +
"()' definition at line " + itos(setter->line) + ".",
v.line);
@ -7429,7 +7430,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
found_getter = true;
FunctionNode *getter = p_class->functions[j];
if (getter->arguments.size() != 0) {
if (getter->get_required_argument_count() != 0) {
_set_error("Getter function can't receive arguments. See '" + getter->name +
"()' definition at line " + itos(getter->line) + ".",
v.line);

View file

@ -219,6 +219,7 @@ public:
virtual DataType get_datatype() const { return return_type; }
virtual void set_datatype(const DataType &p_datatype) { return_type = p_datatype; }
int get_required_argument_count() { return arguments.size() - default_values.size(); }
FunctionNode() {
type = TYPE_FUNCTION;