Re: Patch 9.0.0366

2022-09-03 Fir de Conversatie Bram Moolenaar


John Marriott wrote:

> 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:
> 
> 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;
>    | ^~
> 
> 
> The attached patch tries to fix it.

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.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@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///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220903205429.71ED61C0CE4%40moolenaar.net.


Re: Patch 9.0.0366

2022-09-03 Fir de Conversatie John Marriott


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:

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;
  | ^~


The attached patch tries to fix it.

Cheers
John

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/bfb5875b-93ea-e182-6529-6a66a6c9d286%40internode.on.net.
--- eval.c.orig 2022-09-04 05:09:47.575898000 +1000
+++ eval.c  2022-09-04 05:13:40.942988700 +1000
@@ -694,7 +694,7 @@
 {
 typval_T   ref;
 char_u *name = *arg;
-intsave_flags;
+intsave_flags = 0;
 
 ref.v_type = VAR_UNKNOWN;
 if (evalarg != NULL)


Patch 9.0.0366

2022-09-03 Fir de Conversatie Bram Moolenaar


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 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 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.vim2022-09-02 
21:55:45.511049444 +0100
--- src/testdir/test_vim9_import.vim2022-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 -- b...@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///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220903110946.307111C0CE4%40moolenaar.net.