0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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)
This commit is contained in:
Bram Moolenaar
2023-04-01 22:05:38 +01:00
parent 38d867f041
commit 2ed57ac367
4 changed files with 48 additions and 9 deletions

View File

@@ -752,6 +752,31 @@ def Test_call_default_args()
v9.CheckScriptSuccess(lines) v9.CheckScriptSuccess(lines)
enddef enddef
def Test_using_vnone_default()
var lines =<< trim END
vim9script
def F(a: string = v:none)
if a isnot v:none
var b = a
endif
enddef
F()
END
v9.CheckScriptSuccess(lines)
# TODO: this should give an error for using a missing argument
# lines =<< trim END
# vim9script
# def F(a: string = v:none)
# var b = a
# enddef
# F()
# END
# v9.CheckScriptFailure(lines, 'E99:')
enddef
def Test_convert_number_to_float() def Test_convert_number_to_float()
var lines =<< trim END var lines =<< trim END
vim9script vim9script

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1436,
/**/ /**/
1435, 1435,
/**/ /**/

View File

@@ -3496,7 +3496,15 @@ exec_instructions(ectx_T *ectx)
case ISN_LOAD: case ISN_LOAD:
if (GA_GROW_FAILS(&ectx->ec_stack, 1)) if (GA_GROW_FAILS(&ectx->ec_stack, 1))
goto theend; 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; ++ectx->ec_stack.ga_len;
break; break;

View File

@@ -485,13 +485,17 @@ get_compare_isn(
return ISN_DROP; return ISN_DROP;
} }
if (isntype == ISN_DROP if (isntype == ISN_DROP
|| ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL || (isntype != ISN_COMPARENULL
&& (((exprtype != EXPR_EQUAL
&& exprtype != EXPR_NEQUAL
&& (vartype1 == VAR_BOOL || vartype1 == VAR_SPECIAL && (vartype1 == VAR_BOOL || vartype1 == VAR_SPECIAL
|| vartype2 == VAR_BOOL || vartype2 == VAR_SPECIAL))) || vartype2 == VAR_BOOL || vartype2 == VAR_SPECIAL)))
|| ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL || ((exprtype != EXPR_EQUAL
&& exprtype != EXPR_IS && exprtype != EXPR_ISNOT && exprtype != EXPR_NEQUAL
&& exprtype != EXPR_IS
&& exprtype != EXPR_ISNOT
&& (vartype1 == VAR_BLOB || vartype2 == VAR_BLOB && (vartype1 == VAR_BLOB || vartype2 == VAR_BLOB
|| vartype1 == VAR_LIST || vartype2 == VAR_LIST)))) || vartype1 == VAR_LIST || vartype2 == VAR_LIST))))))
{ {
semsg(_(e_cannot_compare_str_with_str), semsg(_(e_cannot_compare_str_with_str),
vartype_name(vartype1), vartype_name(vartype2)); vartype_name(vartype1), vartype_name(vartype2));