patch 9.1.2096: Vim9: truthiness issue with objects

Commit: 
https://github.com/vim/vim/commit/4a08c8b5d4729b4d5eafe11886611d2053672384
Author: Yegappan Lakshmanan <[email protected]>
Date:   Mon Jan 19 18:21:12 2026 +0000

    patch 9.1.2096: Vim9: truthiness issue with objects
    
    Problem:  Vim9: truthiness issue with objects
              (kennypete)
    Solution: Return true for an non-null object
              (Yegappan Lakshmanan)
    
    related: #19173
    closes:  #19213
    
    Signed-off-by: Yegappan Lakshmanan <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt
index 57ebec375..a15b19391 100644
--- a/runtime/doc/vim9.txt
+++ b/runtime/doc/vim9.txt
@@ -1,4 +1,4 @@
-*vim9.txt*     For Vim version 9.1.  Last change: 2025 Dec 03
+*vim9.txt*     For Vim version 9.1.  Last change: 2026 Jan 19
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1084,8 +1084,11 @@ empty list and dict is falsy:
        special         true or v:true
        job             when not NULL
        channel         when not NULL
-       class           when not NULL
-       object          when not NULL (TODO: when isTrue() returns true)
+       class           not applicable
+       object          when not NULL
+       enum            not applicable
+       enum value      always
+       typealias       not applicable
 
 The boolean operators "||" and "&&" expect the values to be boolean, zero or
 one: >
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 8e5a53d51..87b821638 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -231,6 +231,38 @@ def Test_expr1_falsy()
   END
   v9.CheckDefAndScriptSuccess(lines)
 
+  # falsy operator with objects and enum values
+  lines =<< trim END
+    vim9script
+    class C
+    endclass
+
+    var c = C.new()
+    assert_equal(c, c ?? 'falsy')
+    assert_equal('truthy', !c ?? 'truthy')
+    assert_equal('falsy', null_object ?? 'falsy')
+    assert_equal(true, !null_object ?? 'truthy')
+
+    enum Color
+      Red,
+      Blue
+    endenum
+    assert_equal(Color.Red, Color.Red ?? 'falsy')
+    assert_equal('truthy', !Color.Red ?? 'truthy')
+
+    def Fn()
+      var c2 = C.new()
+      assert_equal(c2, c2 ?? 'falsy')
+      assert_equal('truthy', !c2 ?? 'truthy')
+      assert_equal('falsy', null_object ?? 'falsy')
+      assert_equal(true, !null_object ?? 'truthy')
+      assert_equal(Color.Red, Color.Red ?? 'falsy')
+      assert_equal('truthy', !Color.Red ?? 'truthy')
+    enddef
+    Fn()
+  END
+  v9.CheckSourceScriptSuccess(lines)
+
   var msg = "White space required before and after '??'"
   call v9.CheckDefAndScriptFailure(["var x = 1?? 'one' : 'two'"], msg, 1)
   call v9.CheckDefAndScriptFailure(["var x = 1 ??'one' : 'two'"], msg, 1)
diff --git a/src/version.c b/src/version.c
index 4b9fa37d7..cbf48413c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2096,
 /**/
     2095,
 /**/
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 2b2d59ad5..9763cd95b 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -8127,12 +8127,15 @@ tv2bool(typval_T *tv)
 #endif
        case VAR_BLOB:
            return tv->vval.v_blob != NULL && tv->vval.v_blob->bv_ga.ga_len > 0;
+
+       case VAR_OBJECT:
+           return tv->vval.v_object != NULL;
+
        case VAR_UNKNOWN:
        case VAR_ANY:
        case VAR_VOID:
        case VAR_INSTR:
        case VAR_CLASS:
-       case VAR_OBJECT:
        case VAR_TYPEALIAS:
            break;
     }

-- 
-- 
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 visit 
https://groups.google.com/d/msgid/vim_dev/E1vhu0s-003WVU-T8%40256bit.org.

Raspunde prin e-mail lui