]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1223: Vim9: invalid type error for function default value v8.2.1223
authorBram Moolenaar <Bram@vim.org>
Wed, 15 Jul 2020 17:48:20 +0000 (19:48 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 15 Jul 2020 17:48:20 +0000 (19:48 +0200)
Problem:    Vim9: invalid type error for function default value.
Solution:   Use right argument index. (closes #6458)

src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index f9c5a2af2d98c5f425cf66c2132c160cb1c56b73..3e90a02b809e5b3636b75af6dbaa82acd05840d4 100644 (file)
@@ -104,11 +104,19 @@ def MyDefaultArgs(name = 'string'): string
   return name
 enddef
 
+def MyDefaultSecond(name: string, second: bool  = true): string
+  return second ? name : 'none'
+enddef
+
 def Test_call_default_args()
   assert_equal('string', MyDefaultArgs())
   assert_equal('one', MyDefaultArgs('one'))
   assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
 
+  assert_equal('test', MyDefaultSecond('test'))
+  assert_equal('test', MyDefaultSecond('test', true))
+  assert_equal('none', MyDefaultSecond('test', false))
+
   CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
   CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: argument 1: type mismatch, expected number but got string')
 enddef
index 558a73e8487467401ec1e3cc2d21314a335b0df0..92cbe501d30d4fbdcdc752ea859f4f20dfd2b72f 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1223,
 /**/
     1222,
 /**/
index 39190c972595144bcc682b631ffc74e8b5481d42..ec940df73aed84bdd31091f125602175e446d03b 100644 (file)
@@ -6865,7 +6865,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
            val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
            if (ufunc->uf_arg_types[arg_idx] == &t_unknown)
                ufunc->uf_arg_types[arg_idx] = val_type;
-           else if (check_type(ufunc->uf_arg_types[i], val_type, FALSE)
+           else if (check_type(ufunc->uf_arg_types[arg_idx], val_type, FALSE)
                                                                       == FAIL)
            {
                arg_type_mismatch(ufunc->uf_arg_types[arg_idx], val_type,