Patch 8.2.0659

11 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 28, 2020, 4:50:25 PM4/28/20
to vim...@googlegroups.com

Patch 8.2.0659
Problem: Vim9: no test for equal func type.
Solution: Add a test. Improve type check.
Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.0658/src/vim9compile.c 2020-04-28 21:29:30.625687348 +0200
--- src/vim9compile.c 2020-04-28 22:47:57.700126766 +0200
***************
*** 724,730 ****
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr(cctx, ISN_CHECKTYPE)) == NULL)
return FAIL;
! isn->isn_arg.type.ct_type = vartype->tt_type; // TODO: whole type
isn->isn_arg.type.ct_off = offset;

// type becomes vartype
--- 724,731 ----
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr(cctx, ISN_CHECKTYPE)) == NULL)
return FAIL;
! // TODO: whole type, e.g. for a function also arg and return types
! isn->isn_arg.type.ct_type = vartype->tt_type;
isn->isn_arg.type.ct_off = offset;

// type becomes vartype
***************
*** 2594,2599 ****
--- 2595,2601 ----

/*
* Check if the expected and actual types match.
+ * Does not allow for assigning "any" to a specific type.
*/
static int
check_type(type_T *expected, type_T *actual, int give_msg)
***************
*** 2603,2609 ****
// When expected is "unknown" we accept any actual type.
// When expected is "any" we accept any actual type except "void".
if (expected->tt_type != VAR_UNKNOWN
! && (expected->tt_type != VAR_ANY || actual->tt_type == VAR_VOID))
{
if (expected->tt_type != actual->tt_type)
{
--- 2605,2612 ----
// When expected is "unknown" we accept any actual type.
// When expected is "any" we accept any actual type except "void".
if (expected->tt_type != VAR_UNKNOWN
! && !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
!
{
if (expected->tt_type != actual->tt_type)
{
***************
*** 2643,2649 ****
{
if (check_type(expected, actual, FALSE) == OK)
return OK;
! if (actual->tt_type != VAR_ANY && actual->tt_type != VAR_UNKNOWN)
{
type_mismatch(expected, actual);
return FAIL;
--- 2646,2655 ----
{
if (check_type(expected, actual, FALSE) == OK)
return OK;
! if (actual->tt_type != VAR_ANY
! && actual->tt_type != VAR_UNKNOWN
! && !(actual->tt_type == VAR_FUNC
! && (actual->tt_member == &t_any || actual->tt_argcount < 0)))
{
type_mismatch(expected, actual);
return FAIL;
*** ../vim-8.2.0658/src/testdir/test_vim9_expr.vim 2020-04-28 21:29:30.625687348 +0200
--- src/testdir/test_vim9_expr.vim 2020-04-28 22:16:25.075907196 +0200
***************
*** 30,35 ****
--- 30,45 ----
assert_equal('two', {} ? 'one' : 'two')
var = 0
assert_equal('two', var ? 'one' : 'two')
+
+ let Some: func = function('len')
+ let Other: func = function('winnr')
+ let Res: func = g:atrue ? Some : Other
+ assert_equal(function('len'), Res)
+
+ let RetOne: func(string): number = function('len')
+ let RetTwo: func(string): number = function('winnr')
+ let RetThat: func = g:atrue ? RetOne : RetTwo
+ assert_equal(function('len'), RetThat)
enddef

func Test_expr1_fails()
*** ../vim-8.2.0658/src/version.c 2020-04-28 21:58:25.174049447 +0200
--- src/version.c 2020-04-28 22:48:39.604053087 +0200
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 659,
/**/

--
How To Keep A Healthy Level Of Insanity:
13. Go to a poetry recital and ask why the poems don't rhyme.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages