diff src/vim9type.c @ 27503:4cea92e99a5a v8.2.4279

patch 8.2.4279: Vim9: cannot change item type with map() after range() Commit: https://github.com/vim/vim/commit/8133018f50bc447570825801e93d5ed67e8dac90 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 1 12:11:58 2022 +0000 patch 8.2.4279: Vim9: cannot change item type with map() after range() Problem: Vim9: cannot change item type with map() after range(). Solution: Split the return type in current type and declared type. (closes #9665)
author Bram Moolenaar <Bram@vim.org>
date Tue, 01 Feb 2022 13:15:03 +0100
parents 374c7d5a096a
children f00a7a2bee21
line wrap: on
line diff
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -357,8 +357,10 @@ typval2type_int(typval_T *tv, int copyID
 
 	    if (idx >= 0)
 	    {
+		type_T *decl_type;  // unused
+
 		internal_func_get_argcount(idx, &argcount, &min_argcount);
-		member_type = internal_func_ret_type(idx, 0, NULL);
+		member_type = internal_func_ret_type(idx, 0, NULL, &decl_type);
 	    }
 	    else
 		ufunc = find_func(name, FALSE);
@@ -1244,7 +1246,8 @@ set_type_on_stack(cctx_T *cctx, type_T *
 }
 
 /*
- * Get the type from the type stack.  If "offset" is zero the one at the top,
+ * Get the current type from the type stack.  If "offset" is zero the one at
+ * the top,
  * if "offset" is one the type above that, etc.
  * Returns &t_unknown if there is no such stack entry.
  */
@@ -1260,6 +1263,23 @@ get_type_on_stack(cctx_T *cctx, int offs
 }
 
 /*
+ * Get the declared type from the type stack.  If "offset" is zero the one at
+ * the top,
+ * if "offset" is one the type above that, etc.
+ * Returns &t_unknown if there is no such stack entry.
+ */
+    type_T *
+get_decl_type_on_stack(cctx_T *cctx, int offset)
+{
+    garray_T	*stack = &cctx->ctx_type_stack;
+
+    if (offset + 1 > stack->ga_len)
+	return &t_unknown;
+    return (((type2_T *)stack->ga_data) + stack->ga_len - offset - 1)
+								   ->type_decl;
+}
+
+/*
  * Get the member type of a dict or list from the items on the stack of "cctx".
  * The declared type is stored in "decl_type".
  * For a list "skip" is 1, for a dict "skip" is 2, keys are skipped.