From cb39db0b02c2d69994e2cd523844a2a9d3087d85 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 3 Jan 2016 21:11:11 -0300 Subject: [PATCH] Fixed bug with default arguments in gdscript, closes #2024 --- modules/gdscript/gd_compiler.cpp | 3 ++- modules/gdscript/gd_script.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 6180c668ef6..53519030fc6 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1253,6 +1253,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * StringName func_name; if (p_func) { + if (p_func->default_values.size()) { codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT); @@ -1346,7 +1347,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * if (defarg_addr.size()) { gdfunc->default_arguments=defarg_addr; - gdfunc->_default_arg_count=defarg_addr.size(); + gdfunc->_default_arg_count=defarg_addr.size()-1; gdfunc->_default_arg_ptr=&gdfunc->default_arguments[0]; } else { gdfunc->_default_arg_count=0; diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 03e79393e24..d753a9f167c 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -221,6 +221,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a r_err.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; r_err.argument=_argument_count; + return Variant(); } else if (p_argcount < _argument_count - _default_arg_count) {