diff src/vim9execute.c @ 22284:6b385c2b9ff5 v8.2.1691

patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected Commit: https://github.com/vim/vim/commit/5e654230777ad21363a929dce3cfe0387da031a7 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 16 15:22:00 2020 +0200 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected Problem: Vim9: list<any> is not accepted where list<number> is expected. Solution: Add functions to allocate and free a type_T, use it in ISN_CHECKTYPE. (closes #6959)
author Bram Moolenaar <Bram@vim.org>
date Wed, 16 Sep 2020 15:30:07 +0200
parents eb1f5f618c75
children 3515f341e8ac
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2535,30 +2535,19 @@ call_def_function(
 		    checktype_T *ct = &iptr->isn_arg.type;
 
 		    tv = STACK_TV_BOT(ct->ct_off);
-		    // TODO: better type comparison
-		    if (tv->v_type != ct->ct_type
-			    && !((tv->v_type == VAR_PARTIAL
-						   && ct->ct_type == VAR_FUNC)
-				|| (tv->v_type == VAR_FUNC
-					       && ct->ct_type == VAR_PARTIAL)))
+		    SOURCING_LNUM = iptr->isn_lnum;
+		    if (check_typval_type(ct->ct_type, tv, 0) == FAIL)
+			goto on_error;
+
+		    // number 0 is FALSE, number 1 is TRUE
+		    if (tv->v_type == VAR_NUMBER
+			    && ct->ct_type->tt_type == VAR_BOOL
+			    && (tv->vval.v_number == 0
+						|| tv->vval.v_number == 1))
 		    {
-			if (tv->v_type == VAR_NUMBER && ct->ct_type == VAR_BOOL
-				&& (tv->vval.v_number == 0
-						    || tv->vval.v_number == 1))
-			{
-			    // number 0 is FALSE, number 1 is TRUE
-			    tv->v_type = VAR_BOOL;
-			    tv->vval.v_number = tv->vval.v_number
+			tv->v_type = VAR_BOOL;
+			tv->vval.v_number = tv->vval.v_number
 						      ? VVAL_TRUE : VVAL_FALSE;
-			}
-			else
-			{
-			    SOURCING_LNUM = iptr->isn_lnum;
-			    semsg(_(e_expected_str_but_got_str),
-					vartype_name(ct->ct_type),
-					vartype_name(tv->v_type));
-			    goto on_error;
-			}
 		    }
 		}
 		break;
@@ -3286,10 +3275,16 @@ ex_disassemble(exarg_T *eap)
 	    case ISN_NEGATENR: smsg("%4d NEGATENR", current); break;
 
 	    case ISN_CHECKNR: smsg("%4d CHECKNR", current); break;
-	    case ISN_CHECKTYPE: smsg("%4d CHECKTYPE %s stack[%d]", current,
-				      vartype_name(iptr->isn_arg.type.ct_type),
-				      iptr->isn_arg.type.ct_off);
-				break;
+	    case ISN_CHECKTYPE:
+		  {
+		      char *tofree;
+
+		      smsg("%4d CHECKTYPE %s stack[%d]", current,
+			      type_name(iptr->isn_arg.type.ct_type, &tofree),
+			      iptr->isn_arg.type.ct_off);
+		      vim_free(tofree);
+		      break;
+		  }
 	    case ISN_CHECKLEN: smsg("%4d CHECKLEN %s%d", current,
 				iptr->isn_arg.checklen.cl_more_OK ? ">= " : "",
 				iptr->isn_arg.checklen.cl_min_len);