diff src/vim9type.c @ 25126:b825efff9790 v8.2.3100

patch 8.2.3100: Vim9: no error when using type with unknown number of args Commit: https://github.com/vim/vim/commit/7a40ff00edd35cc4313d74a43e7a7b67cd24372d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 4 15:54:08 2021 +0200 patch 8.2.3100: Vim9: no error when using type with unknown number of args Problem: Vim9: no error when using type with unknown number of arguments. Solution: Do not ignore argument count of -1. (closes https://github.com/vim/vim/issues/8492)
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Jul 2021 16:00:03 +0200
parents 0136c6ee1961
children 5731bcaaabcb
line wrap: on
line diff
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -260,6 +260,7 @@ typval2type_int(typval_T *tv, int copyID
     type_T  *type;
     type_T  *member_type = &t_any;
     int	    argcount = 0;
+    int	    min_argcount = 0;
 
     if (tv->v_type == VAR_NUMBER)
 	return &t_number;
@@ -337,8 +338,7 @@ typval2type_int(typval_T *tv, int copyID
 
 	    if (idx >= 0)
 	    {
-		// TODO: get actual arg count and types
-		argcount = -1;
+		internal_func_get_argcount(idx, &argcount, &min_argcount);
 		member_type = internal_func_ret_type(idx, 0, NULL);
 	    }
 	    else
@@ -364,6 +364,7 @@ typval2type_int(typval_T *tv, int copyID
 	return NULL;
     type->tt_type = tv->v_type;
     type->tt_argcount = argcount;
+    type->tt_min_argcount = min_argcount;
     type->tt_member = member_type;
 
     return type;
@@ -525,9 +526,9 @@ check_type(type_T *expected, type_T *act
 		ret = check_type(expected->tt_member, actual->tt_member,
 								 FALSE, where);
 	    if (ret == OK && expected->tt_argcount != -1
-		    && actual->tt_argcount != -1
-		    && (actual->tt_argcount < expected->tt_min_argcount
-			|| actual->tt_argcount > expected->tt_argcount))
+		    && (actual->tt_argcount == -1
+			|| (actual->tt_argcount < expected->tt_min_argcount
+			    || actual->tt_argcount > expected->tt_argcount)))
 		ret = FAIL;
 	    if (ret == OK && expected->tt_args != NULL
 						    && actual->tt_args != NULL)
@@ -1032,7 +1033,10 @@ common_type(type_T *type1, type_T *type2
 		}
 	    }
 	    else
+		// Use -1 for "tt_argcount" to indicate an unknown number of
+		// arguments.
 		*dest = alloc_func_type(common, -1, type_gap);
+
 	    // Use the minimum of min_argcount.
 	    (*dest)->tt_min_argcount =
 			type1->tt_min_argcount < type2->tt_min_argcount