]> granicus.if.org Git - vim/commitdiff
patch 9.0.1188: return value of type() for class and object unclear v9.0.1188
authorBram Moolenaar <Bram@vim.org>
Thu, 12 Jan 2023 21:08:53 +0000 (21:08 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 12 Jan 2023 21:08:53 +0000 (21:08 +0000)
Problem:    Return value of type() for class and object unclear.
Solution:   Add v:t_object and v:t_class.

runtime/doc/builtin.txt
runtime/doc/eval.txt
src/evalvars.c
src/testdir/test_vim9_class.vim
src/version.c
src/vim.h

index ea3ce61e91eea5bb37f1cf230af6971d1316508e..f202da0585138e78a2dd278851a6522d69fb2aa5 100644 (file)
@@ -9947,6 +9947,8 @@ type({expr})      The result is a Number representing the type of {expr}.
                        Job:        8  |v:t_job|
                        Channel:    9  |v:t_channel|
                        Blob:      10  |v:t_blob|
+                       Class      12  |v:t_class|
+                       Object     13  |v:t_object|
                For backward compatibility, this method can be used: >
                        :if type(myvar) == type(0)
                        :if type(myvar) == type("")
index 556b171561d856f4ddc60bd0da3399ec32c0b83d..5fff3e8598f439c9d5d9864e2b92914fad02bbb9 100644 (file)
@@ -2504,6 +2504,10 @@ v:t_number       Value of |Number| type.  Read-only.  See: |type()|
 v:t_string     Value of |String| type.  Read-only.  See: |type()|
                                        *v:t_blob* *t_blob-variable*
 v:t_blob       Value of |Blob| type.  Read-only.  See: |type()|
+                                       *v:t_class* *t_class-variable*
+v:t_class      Value of |class| type.  Read-only.  See: |type()|
+                                       *v:t_object* *t_object-variable*
+v:t_object     Value of |object| type.  Read-only.  See: |type()|
 
                                *v:termresponse* *termresponse-variable*
 v:termresponse The escape sequence returned by the terminal for the |t_RV|
index 8061a5096dac744d5f2dc935005b636dc094eef3..68df1cb52e285fb21f5f9131ba70dd56a8ca0a9b 100644 (file)
@@ -139,6 +139,8 @@ static struct vimvar
     {VV_NAME("t_job",           VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("t_channel",       VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("t_blob",          VAR_NUMBER), NULL, VV_RO},
+    {VV_NAME("t_class",                 VAR_NUMBER), NULL, VV_RO},
+    {VV_NAME("t_object",        VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("termrfgresp",     VAR_STRING), NULL, VV_RO},
     {VV_NAME("termrbgresp",     VAR_STRING), NULL, VV_RO},
     {VV_NAME("termu7resp",      VAR_STRING), NULL, VV_RO},
@@ -255,6 +257,8 @@ evalvars_init(void)
     set_vim_var_nr(VV_TYPE_JOB,     VAR_TYPE_JOB);
     set_vim_var_nr(VV_TYPE_CHANNEL, VAR_TYPE_CHANNEL);
     set_vim_var_nr(VV_TYPE_BLOB,    VAR_TYPE_BLOB);
+    set_vim_var_nr(VV_TYPE_CLASS,   VAR_TYPE_CLASS);
+    set_vim_var_nr(VV_TYPE_OBJECT,  VAR_TYPE_OBJECT);
 
     set_vim_var_nr(VV_ECHOSPACE,    sc_col - 1);
 
index c6c583a5458de8e93302a8a88ff05f21652036e1..4c10fefd9ebbd7422a1bb4380ebfb3d5c316e3e0 100644 (file)
@@ -155,6 +155,11 @@ def Test_class_basic()
 
       # call an object method
       assert_equal('(2, 12)', pos.ToString())
+
+      assert_equal(v:t_class, type(TextPosition))
+      assert_equal(v:t_object, type(pos))
+      assert_equal('class<TextPosition>', typename(TextPosition))
+      assert_equal('object<TextPosition>', typename(pos))
   END
   v9.CheckScriptSuccess(lines)
 enddef
index ee42263c3d029a97a6d55ea38dc7c507fca56546..1d81e7b6fd3d8ad59fc10a4f1892f97322237989 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1188,
 /**/
     1187,
 /**/
index 33122d7b5650e20463006d6c79576a18ba5b2827..655935fa57d8e2be14e81e921471b6fd0321649f 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2083,23 +2083,25 @@ typedef int sock_T;
 #define VV_TYPE_JOB    85
 #define VV_TYPE_CHANNEL        86
 #define VV_TYPE_BLOB   87
-#define VV_TERMRFGRESP 88
-#define VV_TERMRBGRESP 89
-#define VV_TERMU7RESP  90
-#define VV_TERMSTYLERESP 91
-#define VV_TERMBLINKRESP 92
-#define VV_EVENT       93
-#define VV_VERSIONLONG 94
-#define VV_ECHOSPACE   95
-#define VV_ARGV                96
-#define VV_COLLATE      97
-#define VV_EXITING     98
-#define VV_COLORNAMES   99
-#define VV_SIZEOFINT   100
-#define VV_SIZEOFLONG  101
-#define VV_SIZEOFPOINTER 102
-#define VV_MAXCOL      103
-#define VV_LEN         104     // number of v: vars
+#define VV_TYPE_CLASS  88
+#define VV_TYPE_OBJECT 89
+#define VV_TERMRFGRESP 90
+#define VV_TERMRBGRESP 91
+#define VV_TERMU7RESP  92
+#define VV_TERMSTYLERESP 93
+#define VV_TERMBLINKRESP 94
+#define VV_EVENT       95
+#define VV_VERSIONLONG 96
+#define VV_ECHOSPACE   97
+#define VV_ARGV                98
+#define VV_COLLATE      99
+#define VV_EXITING     100
+#define VV_COLORNAMES   101
+#define VV_SIZEOFINT   102
+#define VV_SIZEOFLONG  103
+#define VV_SIZEOFPOINTER 104
+#define VV_MAXCOL      105
+#define VV_LEN         106     // number of v: vars
 
 // used for v_number in VAR_BOOL and VAR_SPECIAL
 #define VVAL_FALSE     0L      // VAR_BOOL