From: Yegappan Lakshmanan Date: Tue, 20 Jan 2026 19:46:33 +0000 (+0000) Subject: patch 9.1.2101: Vim9: more truthiness issues X-Git-Tag: v9.1.2101^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7d195415b31ca6168501cac3506e65beb484ada;p=thirdparty%2Fvim.git patch 9.1.2101: Vim9: more truthiness issues 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 Signed-off-by: Christian Brabandt --- diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index 87b8216386..b663728849 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -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 + echo T1 ?? 'falsy' + END + v9.CheckSourceScriptFailure(lines, 'E1403: Type alias "T1" cannot be used as a value') + + lines =<< trim END + vim9script + type T2 = list + 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) diff --git a/src/version.c b/src/version.c index 61720c9361..d6644bf10c 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 */ +/**/ + 2101, /**/ 2100, /**/ diff --git a/src/vim9execute.c b/src/vim9execute.c index 9763cd95b1..bdea74f66a 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -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;