Merge pull request #25018 from AllanDaemon/#24895
Fix support for optional parameters in setters
This commit is contained in:
commit
755c690252
2 changed files with 4 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue