diff options
author | George Marques <george@gmarqu.es> | 2019-02-24 10:45:50 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-24 10:45:50 -0300 |
commit | 755c69025295291d3a361e336f9289edb6634f4d (patch) | |
tree | 645fca77d0cbdc4f77020e8fcbcc88cc4844145b /modules | |
parent | ab8f3d7842976b7fccc6df7abe11d13b44a134f9 (diff) | |
parent | 465842d8ea53904447ead9164065268842a15d71 (diff) |
Merge pull request #25018 from AllanDaemon/#24895
Fix support for optional parameters in setters
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 5 | ||||
-rw-r--r-- | 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 705f39ae78..adbd7e4e04 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -7458,7 +7458,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); @@ -7477,7 +7478,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 5ded4668a7..9c1ea1c7e4 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -221,6 +221,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; |