summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-01-12 21:08:53 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-12 21:08:53 +0000
commitc0c2c262650103c4a21b64c3246388a350688616 (patch)
treec47119d4200782f8378d5c88595d711f08bd8d9f
parent3ce33b120c6479dfc8f22c7cc8945b9ef54285b0 (diff)
patch 9.0.1188: return value of type() for class and object unclearv9.0.1188
Problem: Return value of type() for class and object unclear. Solution: Add v:t_object and v:t_class.
-rw-r--r--runtime/doc/builtin.txt2
-rw-r--r--runtime/doc/eval.txt4
-rw-r--r--src/evalvars.c4
-rw-r--r--src/testdir/test_vim9_class.vim5
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h36
6 files changed, 36 insertions, 17 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index ea3ce61e91..f202da0585 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -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("")
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 556b171561..5fff3e8598 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -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|
diff --git a/src/evalvars.c b/src/evalvars.c
index 8061a5096d..68df1cb52e 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -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);
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index c6c583a545..4c10fefd9e 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index ee42263c3d..1d81e7b6fd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1188,
+/**/
1187,
/**/
1186,
diff --git a/src/vim.h b/src/vim.h
index 33122d7b56..655935fa57 100644
--- 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