changeset 30721:030bdef24446 v9.0.0695

patch 9.0.0695: failing check for dictionary type for const any Commit: https://github.com/vim/vim/commit/0089ce293f885afc2b77f12aa110f33b2101973a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 8 14:39:36 2022 +0100 patch 9.0.0695: failing check for dictionary type for const any Problem: Failing check for dictionary type for const any. Solution: Check for any type properly. (closes https://github.com/vim/vim/issues/11310)
author Bram Moolenaar <Bram@vim.org>
date Sat, 08 Oct 2022 15:45:03 +0200
parents 763b6d18b527
children 0dbffb118f79
files src/testdir/test_vim9_script.vim src/version.c src/vim9instr.c
diffstat 3 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -297,6 +297,14 @@ def Test_const()
     constdict->assert_equal({one: 1, two: {five: 55, six: 66}, three: 3})
   END
   v9.CheckDefAndScriptSuccess(lines)
+
+  # "any" type with const flag is recognized as "any"
+  lines =<< trim END
+      const dict: dict<any> = {foo: {bar: 42}}
+      const foo = dict.foo
+      assert_equal(v:t_number, type(foo.bar))
+  END
+  v9.CheckDefAndScriptSuccess(lines)
 enddef
 
 def Test_const_bang()
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    695,
+/**/
     694,
 /**/
     693,
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -1831,7 +1831,8 @@ generate_STRINGMEMBER(cctx_T *cctx, char
 
     // check for dict type
     type = get_type_on_stack(cctx, 0);
-    if (type->tt_type != VAR_DICT && type != &t_any && type != &t_unknown)
+    if (type->tt_type != VAR_DICT
+		   && type->tt_type != VAR_ANY && type->tt_type != VAR_UNKNOWN)
     {
 	char *tofree;
 
@@ -1843,7 +1844,7 @@ generate_STRINGMEMBER(cctx_T *cctx, char
     // change dict type to dict member type
     if (type->tt_type == VAR_DICT)
     {
-	type_T *ntype = type->tt_member == &t_unknown
+	type_T *ntype = type->tt_member->tt_type == VAR_UNKNOWN
 						    ? &t_any : type->tt_member;
 	set_type_on_stack(cctx, ntype, 0);
     }