• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Révision374c7d5a096aefa941ac5ff0d16df365868be44d (tree)
l'heure2022-01-17 03:15:03
AuteurBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Message de Log

patch 8.2.4114: Vim9: type checking for a funcref does not work for method

Commit: https://github.com/vim/vim/commit/c84287d6d8dd055bb6e30605465a23a8addb6fde
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 16 18:06:21 2022 +0000

patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Problem: Vim9: type checking for a funcref does not work for when it is
used in a method.
Solution: Pass the base to where the type is checked.

Change Summary

Modification

diff -r 14d0c1d33701 -r 374c7d5a096a src/proto/vim9type.pro
--- a/src/proto/vim9type.pro Sun Jan 16 17:00:05 2022 +0100
+++ b/src/proto/vim9type.pro Sun Jan 16 19:15:03 2022 +0100
@@ -12,12 +12,11 @@
1212 type_T *typval2type_vimvar(typval_T *tv, garray_T *type_gap);
1313 int check_typval_arg_type(type_T *expected, typval_T *actual_tv, char *func_name, int arg_idx);
1414 int check_typval_type(type_T *expected, typval_T *actual_tv, where_T where);
15-void type_mismatch(type_T *expected, type_T *actual);
1615 void arg_type_mismatch(type_T *expected, type_T *actual, int arg_idx);
1716 void type_mismatch_where(type_T *expected, type_T *actual, where_T where);
1817 int check_type(type_T *expected, type_T *actual, int give_msg, where_T where);
1918 int check_type_maybe(type_T *expected, type_T *actual, int give_msg, where_T where);
20-int check_argument_types(type_T *type, typval_T *argvars, int argcount, char_u *name);
19+int check_argument_types(type_T *type, typval_T *argvars, int argcount, typval_T *base_tv, char_u *name);
2120 char_u *skip_type(char_u *start, int optional);
2221 type_T *parse_type(char_u **arg, garray_T *type_gap, int give_error);
2322 int equal_type(type_T *type1, type_T *type2, int flags);
diff -r 14d0c1d33701 -r 374c7d5a096a src/testdir/test_vim9_expr.vim
--- a/src/testdir/test_vim9_expr.vim Sun Jan 16 17:00:05 2022 +0100
+++ b/src/testdir/test_vim9_expr.vim Sun Jan 16 19:15:03 2022 +0100
@@ -3136,6 +3136,14 @@
31363136 var sorted = [3, 1, 2]
31373137 -> sort()
31383138 assert_equal([1, 2, 3], sorted)
3139+
3140+ def SetNumber(n: number)
3141+ g:number = n
3142+ enddef
3143+ const Setit = SetNumber
3144+ len('text')->Setit()
3145+ assert_equal(4, g:number)
3146+ unlet g:number
31393147 END
31403148 CheckDefAndScriptSuccess(lines)
31413149
diff -r 14d0c1d33701 -r 374c7d5a096a src/userfunc.c
--- a/src/userfunc.c Sun Jan 16 17:00:05 2022 +0100
+++ b/src/userfunc.c Sun Jan 16 19:15:03 2022 +0100
@@ -3386,7 +3386,8 @@
33863386 && funcexe->fe_evaluate)
33873387 {
33883388 // Check that the argument types are OK for the types of the funcref.
3389- if (check_argument_types(funcexe->fe_check_type, argvars, argcount,
3389+ if (check_argument_types(funcexe->fe_check_type,
3390+ argvars, argcount, funcexe->fe_basetv,
33903391 (name != NULL) ? name : funcname) == FAIL)
33913392 error = FCERR_OTHER;
33923393 }
diff -r 14d0c1d33701 -r 374c7d5a096a src/version.c
--- a/src/version.c Sun Jan 16 17:00:05 2022 +0100
+++ b/src/version.c Sun Jan 16 19:15:03 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4114,
755+/**/
754756 4113,
755757 /**/
756758 4112,
diff -r 14d0c1d33701 -r 374c7d5a096a src/vim9type.c
--- a/src/vim9type.c Sun Jan 16 17:00:05 2022 +0100
+++ b/src/vim9type.c Sun Jan 16 19:15:03 2022 +0100
@@ -687,6 +687,7 @@
687687
688688 /*
689689 * Check that the arguments of "type" match "argvars[argcount]".
690+ * "base_tv" is from "expr->Func()".
690691 * Return OK/FAIL.
691692 */
692693 int
@@ -694,19 +695,21 @@
694695 type_T *type,
695696 typval_T *argvars,
696697 int argcount,
698+ typval_T *base_tv,
697699 char_u *name)
698700 {
699701 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;
700702 int i;
703+ int totcount = argcount + (base_tv == NULL ? 0 : 1);
701704
702705 if (type->tt_type != VAR_FUNC && type->tt_type != VAR_PARTIAL)
703706 return OK; // just in case
704- if (argcount < type->tt_min_argcount - varargs)
707+ if (totcount < type->tt_min_argcount - varargs)
705708 {
706709 semsg(_(e_not_enough_arguments_for_function_str), name);
707710 return FAIL;
708711 }
709- if (!varargs && type->tt_argcount >= 0 && argcount > type->tt_argcount)
712+ if (!varargs && type->tt_argcount >= 0 && totcount > type->tt_argcount)
710713 {
711714 semsg(_(e_too_many_arguments_for_function_str), name);
712715 return FAIL;
@@ -715,15 +718,25 @@
715718 return OK; // cannot check
716719
717720
718- for (i = 0; i < argcount; ++i)
721+ for (i = 0; i < totcount; ++i)
719722 {
720- type_T *expected;
723+ type_T *expected;
724+ typval_T *tv;
721725
726+ if (base_tv != NULL)
727+ {
728+ if (i == 0)
729+ tv = base_tv;
730+ else
731+ tv = &argvars[i - 1];
732+ }
733+ else
734+ tv = &argvars[i];
722735 if (varargs && i >= type->tt_argcount - 1)
723736 expected = type->tt_args[type->tt_argcount - 1]->tt_member;
724737 else
725738 expected = type->tt_args[i];
726- if (check_typval_arg_type(expected, &argvars[i], NULL, i + 1) == FAIL)
739+ if (check_typval_arg_type(expected, tv, NULL, i + 1) == FAIL)
727740 return FAIL;
728741 }
729742 return OK;
Afficher sur ancien navigateur de dépôt.