From 465842d8ea53904447ead9164065268842a15d71 Mon Sep 17 00:00:00 2001 From: Allan Daemon Date: Wed, 16 Jan 2019 01:38:37 -0200 Subject: [PATCH] Fix #24895 (support for optional parameters in setters) --- modules/gdscript/gdscript_parser.cpp | 5 +++-- modules/gdscript/gdscript_parser.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index a012ccad30a..5f920dd4498 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -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); diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index b4a705c9e7f..a25884cf8d1 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -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;