]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2101: Vim9: more truthiness issues v9.1.2101
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 20 Jan 2026 19:46:33 +0000 (19:46 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 20 Jan 2026 19:46:33 +0000 (19:46 +0000)
Problem:  Vim9: more truthiness issues
          (kennypete)
Solution: Class, enum and typealias cannot be used with the falsy
          operator (Yegappan Lakshmanan)

related: #19213
fixes:   #19173
closes:  #19216

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_expr.vim
src/version.c
src/vim9execute.c

index 87b82163869b00e70c3f9a338e5bf404f40403cd..b663728849c2d4896729ec7128e7dfb143b4fc5f 100644 (file)
@@ -263,6 +263,67 @@ def Test_expr1_falsy()
   END
   v9.CheckSourceScriptSuccess(lines)
 
+  # class cannot be used with the falsy operator
+  lines =<< trim END
+    vim9script
+    class A
+    endclass
+    echo A ?? 'falsy'
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1405: Class "A" cannot be used as a value')
+
+  lines =<< trim END
+    vim9script
+    class B
+    endclass
+    echo !B
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1405: Class "B" cannot be used as a value')
+
+  lines =<< trim END
+    vim9script
+    echo null_class ?? 'falsy'
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1405: Class "" cannot be used as a value')
+
+  lines =<< trim END
+    vim9script
+    echo !null_class
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1405: Class "" cannot be used as a value')
+
+  # enum cannot be used with the falsy operator
+  lines =<< trim END
+    vim9script
+    enum E1
+    endenum
+    echo E1 ?? 'falsy'
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1421: Enum "E1" cannot be used as a value')
+
+  lines =<< trim END
+    vim9script
+    enum E2
+    endenum
+    echo !E2
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1421: Enum "E2" cannot be used as a value')
+
+  # typealias cannot be used with the falsy operator
+  lines =<< trim END
+    vim9script
+    type T1 = list<bool>
+    echo T1 ?? 'falsy'
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1403: Type alias "T1" cannot be used as a value')
+
+  lines =<< trim END
+    vim9script
+    type T2 = list<bool>
+    echo !T2
+  END
+  v9.CheckSourceScriptFailure(lines, 'E1403: Type alias "T2" cannot be used as a value')
+
   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)
index 61720c93610ef17e22b476eb4e995a97bc763f01..d6644bf10c378664170dd67962cb8f06070bda15 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2101,
 /**/
     2100,
 /**/
index 9763cd95b1e7cb016e28d8b8d92729823f140e93..bdea74f66a208217e0250773981e0bf6216eddf7 100644 (file)
@@ -8131,12 +8131,15 @@ tv2bool(typval_T *tv)
        case VAR_OBJECT:
            return tv->vval.v_object != NULL;
 
+       case VAR_CLASS:
+       case VAR_TYPEALIAS:
+           check_typval_is_value(tv);
+           break;
+
        case VAR_UNKNOWN:
        case VAR_ANY:
        case VAR_VOID:
        case VAR_INSTR:
-       case VAR_CLASS:
-       case VAR_TYPEALIAS:
            break;
     }
     return FALSE;