*error = FALSE;
if (!skip)
{
- retval = (tv_get_number_chk(&tv, error) != 0);
+ if (in_vim9script())
+ retval = tv2bool(&tv);
+ else
+ retval = (tv_get_number_chk(&tv, error) != 0);
clear_tv(&tv);
}
}
// Apply prefixed "-" and "+" now. Matters especially when
// "->" follows.
- if (ret == OK && evaluate && end_leader > start_leader)
+ if (ret == OK && evaluate && end_leader > start_leader
+ && rettv->v_type != VAR_BLOB)
ret = eval7_leader(rettv, TRUE, start_leader, &end_leader);
break;
f = rettv->vval.v_float;
else
#endif
- val = tv_get_number_chk(rettv, &error);
+ if (in_vim9script() && end_leader[-1] == '!')
+ val = tv2bool(rettv);
+ else
+ val = tv_get_number_chk(rettv, &error);
if (error)
{
clear_tv(rettv);
def Test_expr7_not()
- assert_equal(true, !'')
- assert_equal(true, ![])
- assert_equal(false, !'asdf')
- assert_equal(false, ![2])
- assert_equal(true, !!'asdf')
- assert_equal(true, !![2])
-
- assert_equal(true, !test_null_partial())
- assert_equal(false, !{-> 'yes'})
-
- assert_equal(true, !test_null_dict())
- assert_equal(true, !{})
- assert_equal(false, !{'yes': 'no'})
-
- if has('channel')
- assert_equal(true, !test_null_job())
- assert_equal(true, !test_null_channel())
- endif
-
- assert_equal(true, !test_null_blob())
- assert_equal(true, !0z)
- assert_equal(false, !0z01)
-
- assert_equal(true, !test_void())
- assert_equal(true, !test_unknown())
+ let lines =<< trim END
+ assert_equal(true, !'')
+ assert_equal(true, ![])
+ assert_equal(false, !'asdf')
+ assert_equal(false, ![2])
+ assert_equal(true, !!'asdf')
+ assert_equal(true, !![2])
+
+ assert_equal(true, !test_null_partial())
+ assert_equal(false, !{-> 'yes'})
+
+ assert_equal(true, !test_null_dict())
+ assert_equal(true, !{})
+ assert_equal(false, !{'yes': 'no'})
+
+ if has('channel')
+ assert_equal(true, !test_null_job())
+ assert_equal(true, !test_null_channel())
+ endif
+
+ assert_equal(true, !test_null_blob())
+ assert_equal(true, !0z)
+ assert_equal(false, !0z01)
+
+ assert_equal(true, !test_void())
+ assert_equal(true, !test_unknown())
+ END
+ CheckDefSuccess(lines)
+ CheckScriptSuccess(['vim9script'] + lines)
enddef
func Test_expr7_fails()
" Utility functions for testing vim9 script
+" Check that "lines" inside ":def" has no error.
+func CheckDefSuccess(lines)
+ call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
+ so Xdef
+ call Func()
+ call delete('Xdef')
+endfunc
+
" Check that "lines" inside ":def" results in an "error" message.
func CheckDefFailure(lines, error)
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')