patch 9.0.1436: cannot compare a typed variable with v:none
Problem: Cannot compare a typed variable with v:none.
Solution: Allow for "x is v:none" and "x isnot v:none". (issue #12194)
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 0f28ba0..2965afa 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
Binary files differ
diff --git a/src/version.c b/src/version.c
index 547d6a7..23d4936 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1436,
+/**/
1435,
/**/
1434,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 18cebdb..d558ca0 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -3496,7 +3496,15 @@
case ISN_LOAD:
if (GA_GROW_FAILS(&ectx->ec_stack, 1))
goto theend;
- copy_tv(STACK_TV_VAR(iptr->isn_arg.number), STACK_TV_BOT(0));
+ tv = STACK_TV_VAR(iptr->isn_arg.number);
+ if (tv->v_type == VAR_UNKNOWN)
+ {
+ // missing argument or default value v:none
+ STACK_TV_BOT(0)->v_type = VAR_SPECIAL;
+ STACK_TV_BOT(0)->vval.v_number = VVAL_NONE;
+ }
+ else
+ copy_tv(tv, STACK_TV_BOT(0));
++ectx->ec_stack.ga_len;
break;
diff --git a/src/vim9instr.c b/src/vim9instr.c
index e2cdc3a..52402c1 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -413,7 +413,7 @@
*/
static isntype_T
get_compare_isn(
- exprtype_T exprtype,
+ exprtype_T exprtype,
typval_T *tv1,
typval_T *tv2,
type_T *type1,
@@ -485,13 +485,17 @@
return ISN_DROP;
}
if (isntype == ISN_DROP
- || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL
- && (vartype1 == VAR_BOOL || vartype1 == VAR_SPECIAL
- || vartype2 == VAR_BOOL || vartype2 == VAR_SPECIAL)))
- || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL
- && exprtype != EXPR_IS && exprtype != EXPR_ISNOT
- && (vartype1 == VAR_BLOB || vartype2 == VAR_BLOB
- || vartype1 == VAR_LIST || vartype2 == VAR_LIST))))
+ || (isntype != ISN_COMPARENULL
+ && (((exprtype != EXPR_EQUAL
+ && exprtype != EXPR_NEQUAL
+ && (vartype1 == VAR_BOOL || vartype1 == VAR_SPECIAL
+ || vartype2 == VAR_BOOL || vartype2 == VAR_SPECIAL)))
+ || ((exprtype != EXPR_EQUAL
+ && exprtype != EXPR_NEQUAL
+ && exprtype != EXPR_IS
+ && exprtype != EXPR_ISNOT
+ && (vartype1 == VAR_BLOB || vartype2 == VAR_BLOB
+ || vartype1 == VAR_LIST || vartype2 == VAR_LIST))))))
{
semsg(_(e_cannot_compare_str_with_str),
vartype_name(vartype1), vartype_name(vartype2));