Patch 9.0.0366

6 views
Skip to first unread message

Bram Moolenaar

unread,
Sep 3, 2022, 7:09:59 AM9/3/22
to vim...@googlegroups.com

Patch 9.0.0366
Problem: Cannot use import->Func() in lambda. (Israel Chauca Fuentes)
Solution: Adjust how an expression in a lambda is parsed. (closes #11042)
Files: src/eval.c, src/testdir/test_vim9_import.vim


*** ../vim-9.0.0365/src/eval.c 2022-09-02 12:16:01.876714257 +0100
--- src/eval.c 2022-09-03 11:51:56.237791288 +0100
***************
*** 694,701 ****
--- 694,708 ----
{
typval_T ref;
char_u *name = *arg;
+ int save_flags;

ref.v_type = VAR_UNKNOWN;
+ if (evalarg != NULL)
+ {
+ // need to evaluate this to get an import, like in "a.Func"
+ save_flags = evalarg->eval_flags;
+ evalarg->eval_flags |= EVAL_EVALUATE;
+ }
if (eval9(arg, &ref, evalarg, FALSE) == FAIL)
{
dictitem_T *v;
***************
*** 703,709 ****
// If <SID>VarName was used it would not be found, try another way.
v = find_var_also_in_script(name, NULL, FALSE);
if (v == NULL)
! return NULL;
copy_tv(&v->di_tv, &ref);
}
if (*skipwhite(*arg) != NUL)
--- 710,719 ----
// If <SID>VarName was used it would not be found, try another way.
v = find_var_also_in_script(name, NULL, FALSE);
if (v == NULL)
! {
! name = NULL;
! goto theend;
! }
copy_tv(&v->di_tv, &ref);
}
if (*skipwhite(*arg) != NUL)
***************
*** 739,745 ****
--- 749,759 ----
semsg(_(e_not_callable_type_str), name);
name = NULL;
}
+
+ theend:
clear_tv(&ref);
+ if (evalarg != NULL)
+ evalarg->eval_flags = save_flags;
return name;
}

***************
*** 4080,4086 ****
// Handle following '[', '(' and '.' for expr[expr], expr.name,
// expr(expr), expr->name(expr)
if (ret == OK)
! ret = handle_subscript(arg, name_start, rettv, evalarg, TRUE);

/*
* Apply logical NOT and unary '-', from right to left, ignore '+'.
--- 4094,4100 ----
// Handle following '[', '(' and '.' for expr[expr], expr.name,
// expr(expr), expr->name(expr)
if (ret == OK)
! ret = handle_subscript(arg, name_start, rettv, evalarg, evaluate);

/*
* Apply logical NOT and unary '-', from right to left, ignore '+'.
***************
*** 4349,4355 ****
rettv->v_type = VAR_UNKNOWN;

name = *arg;
! len = get_name_len(arg, &alias, evaluate, TRUE);
if (alias != NULL)
name = alias;

--- 4363,4369 ----
rettv->v_type = VAR_UNKNOWN;

name = *arg;
! len = get_name_len(arg, &alias, evaluate, evaluate);
if (alias != NULL)
name = alias;

*** ../vim-9.0.0365/src/testdir/test_vim9_import.vim 2022-09-02 21:55:45.511049444 +0100
--- src/testdir/test_vim9_import.vim 2022-09-03 11:59:39.368291127 +0100
***************
*** 1454,1459 ****
--- 1454,1481 ----
set nospell spellsuggest& verbose=0
enddef

+ def Test_import_in_lambda_method()
+ var lines =<< trim END
+ vim9script
+ export def Retarg(e: any): any
+ return e
+ enddef
+ END
+ writefile(lines, 'XexportRetarg.vim')
+ lines =<< trim END
+ vim9script
+ import './XexportRetarg.vim'
+ def Lambda(): string
+ var F = (x) => x->XexportRetarg.Retarg()
+ return F('arg')
+ enddef
+ assert_equal('arg', Lambda())
+ END
+ v9.CheckScriptSuccess(lines)
+
+ delete('XexportRetarg.vim')
+ enddef
+
def Test_export_shadows_global_function()
mkdir('Xglobdir/autoload', 'p')
var save_rtp = &rtp
*** ../vim-9.0.0365/src/version.c 2022-09-03 10:59:28.716487461 +0100
--- src/version.c 2022-09-03 11:59:09.912416857 +0100
***************
*** 709,710 ****
--- 709,712 ----
{ /* Add new patch number below this line */
+ /**/
+ 366,
/**/

--
You can test a person's importance in the organization by asking how much RAM
his computer has. Anybody who knows the answer to that question is not a
decision-maker.
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
Sep 3, 2022, 3:18:40 PM9/3/22
to vim...@googlegroups.com

On 03-Sept-2022 21:09, Bram Moolenaar wrote:
> Patch 9.0.0366
> Problem: Cannot use import->Func() in lambda. (Israel Chauca Fuentes)
> Solution: Adjust how an expression in a lambda is parsed. (closes #11042)
> Files: src/eval.c, src/testdir/test_vim9_import.vim
>
>
After this patch mingw64 (gcc 12.2.0) spits out this warning:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD eval.c -o gobjnative/eval.o
In function 'deref_function_name',
    inlined from 'eval_method' at eval.c:4392:14,
    inlined from 'handle_subscript' at eval.c:6451:13:
eval.c:756:29: warning: 'save_flags' may be used uninitialized
[-Wmaybe-uninitialized]
  756 |         evalarg->eval_flags = save_flags;
      |         ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
eval.c: In function 'handle_subscript':
eval.c:697:17: note: 'save_flags' was declared here
  697 |     int         save_flags;
      |                 ^~~~~~~~~~
</snip>

The attached patch tries to fix it.

Cheers
John
eval.c.9.0.0366.patch

Bram Moolenaar

unread,
Sep 3, 2022, 4:54:39 PM9/3/22
to vim...@googlegroups.com, John Marriott
Thanks!

--
The fastest way to get an engineer to solve a problem is to declare that the
problem is unsolvable. No engineer can walk away from an unsolvable problem
until it's solved.
Reply all
Reply to author
Forward
0 new messages