patch 9.1.0136: Vim9: need more test for exists() methods

Commit: 
https://github.com/vim/vim/commit/a2ebb6e9176d007c11804bb9784beee35a8050c8
Author: Yegappan Lakshmanan <[email protected]>
Date:   Sun Feb 25 08:40:10 2024 +0100

    patch 9.1.0136: Vim9: need more test for exists()
    methods
    
    Problem:  Vim9: need more test for exists()
    Solution: Add test for exists() with class/objct variables and methods
              (Yegappan Lakshmanan)
    
    closes: #14088
    
    Signed-off-by: Yegappan Lakshmanan <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 849b1808f..0af9b0e0f 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -1,4 +1,4 @@
-*builtin.txt*  For Vim version 9.1.  Last change: 2024 Feb 24
+*builtin.txt*  For Vim version 9.1.  Last change: 2024 Feb 25
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -2405,11 +2405,11 @@ exists({expr})  The result is a Number, which is |TRUE| 
if {expr} is defined,
                        varname         internal variable (see
                        dict.key        |internal-variables|).  Also works
                        list[i]         for |curly-braces-names|, |Dictionary|
-                       import.Func     entries, |List| items, imported
-                                       items, etc.
-                                       Does not work for local variables in a
-                                       compiled `:def` function.
-                                       Also works for a function in |Vim9|
+                       import.Func     entries, |List| items, class and
+                       class.Func      object methods, imported items, etc.
+                       object.Func     Does not work for local variables in a
+                       class.varname   compiled `:def` function.
+                       object.varname  Also works for a function in |Vim9|
                                        script, since it can be used as a
                                        function reference.
                                        Beware that evaluating an index may
diff --git a/src/testdir/test_exists.vim b/src/testdir/test_exists.vim
index a735a7d19..9cdb3fb5c 100644
--- a/src/testdir/test_exists.vim
+++ b/src/testdir/test_exists.vim
@@ -1,5 +1,7 @@
 " Tests for the exists() function
 
+import './vim9.vim' as v9
+
 func Test_exists()
   augroup myagroup
       autocmd! BufEnter       *.my     echo "myfile edited"
@@ -334,4 +336,51 @@ func Test_exists_funcarg()
   call FuncArg_Tests("arg1", "arg2")
 endfunc
 
+" Test for using exists() with class and object variables and methods.
+func Test_exists_class_object()
+  let lines =<< trim END
+    vim9script
+    class A
+      var var1: number = 10
+      static var var2: number = 10
+      static def Foo()
+      enddef
+      def Bar()
+      enddef
+    endclass
+
+    assert_equal(1, exists("A"))
+    var a = A.new()
+    assert_equal(1, exists("a"))
+
+    assert_equal(1, exists("a.var1"))
+    assert_fails('exists("a.var2")', 'E1375: Class variable "var2" accessible 
only using class "A"')
+    assert_fails('exists("a.var3")', 'E1326: Variable "var3" not found in 
object "A"')
+    assert_equal(1, exists("A.var2"))
+    assert_fails('exists("A.var1")', 'E1376: Object variable "var1" accessible 
only using class "A" object')
+    assert_fails('exists("A.var3")', 'E1337: Class variable "var3" not found 
in class "A"')
+
+    assert_equal(1, exists("a.Bar"))
+    assert_fails('exists("a.Barz")', 'E1326: Variable "Barz" not found in 
object "A"')
+    assert_fails('exists("a.Foo")', 'E1326: Variable "Foo" not found in object 
"A"')
+    assert_equal(1, exists("A.Foo"))
+    assert_fails('exists("A.Bar")', 'E1337: Class variable "Bar" not found in 
class "A"')
+    assert_fails('exists("A.Barz")', 'E1337: Class variable "Barz" not found 
in class "A"')
+
+    def Baz()
+      assert_equal(1, exists("A"))
+      var aa = A.new()
+      assert_equal(1, exists("A.var2"))
+      assert_fails('exists("A.var1")', 'E1376: Object variable "var1" 
accessible only using class "A" object')
+      assert_fails('exists("A.var3")', 'E1337: Class variable "var3" not found 
in class "A"')
+
+      assert_equal(1, exists("A.Foo"))
+      assert_fails('exists("A.Bar")', 'E1337: Class variable "Bar" not found 
in class "A"')
+      assert_fails('exists("A.Barz")', 'E1337: Class variable "Barz" not found 
in class "A"')
+    enddef
+    Baz()
+  END
+  call v9.CheckSourceSuccess(lines)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 7ecfc9444..6d6a5a19a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    136,
 /**/
     135,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1re9C7-000G2P-9H%40256bit.org.

Raspunde prin e-mail lui