Loading ...
Sorry, an error occurred while loading the content.

Re: Vim expr parsing bug

Expand Messages
  • Christian Brabandt
    Hi Bram! ... Well, I am not sure, what caused the segfault for Andy. But I have been checking with him privately, that this patch works and added some tests.
    Message 1 of 9 , Nov 23, 2012
    • 0 Attachment
      Hi Bram!

      On Fr, 23 Nov 2012, Bram Moolenaar wrote:

      >
      > Christian Brabandt wrote:
      >
      > > On Do, 22 Nov 2012, Bram Moolenaar wrote:
      > >
      > > >
      > > > Andy Wokula wrote:
      > > >
      > > > > " Vim Parsing Bug
      > > > >
      > > > > func! Add2(x1, x2)
      > > > > return a:x1 + a:x2
      > > > > endfunc
      > > > >
      > > > > :echo function('Add2')(2,3)
      > > > > " 5 (ok)
      > > > >
      > > > > " Bug:
      > > > > :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
      > > > > :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
      > > > >
      > > > > " Error detected while processing D1223.vim:
      > > > > " line 17:
      > > > > " E110: Missing ')'
      > > > > " E15: Invalid expression: (2,3)
      > > > > " line 18:
      > > > > " E109: Missing ':' after '?'
      > > > > " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
      > > > >
      > > > >
      > > > > Adding parentheses 1 ? (...) : (...) doesn't help.
      > > >
      > > > Strange. I'll add it to the todo list.
      > >
      > > Problem is, in expr1 ? expr2 : expr3
      > > Vim explicitly resets evaluate in the false case which leads to being
      > > rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
      > > the subscript anymore.
      > >
      > > Here is a patch:
      > >
      > > diff --git a/src/eval.c b/src/eval.c
      > > --- a/src/eval.c
      > > +++ b/src/eval.c
      > > @@ -19574,7 +19574,7 @@
      > > while (ret == OK
      > > && (**arg == '['
      > > || (**arg == '.' && rettv->v_type == VAR_DICT)
      > > - || (**arg == '(' && rettv->v_type == VAR_FUNC))
      > > + || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
      > > && !vim_iswhite(*(*arg - 1)))
      > > {
      > > if (**arg == '(')
      >
      > Thanks for the quick fix.
      >
      > Now, how about a test?

      Well, I am not sure, what caused the segfault for Andy. But I have been
      checking with him privately, that this patch works and added some tests.
      So here we go, a different patch, including a test.

      regards,
      Christian
      --

      --
      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
    • Bram Moolenaar
      ... Thanks! -- hundred-and-one symptoms of being an internet addict: 62. If your doorbell rings, you think that new mail has arrived. And then you re
      Message 2 of 9 , Nov 23, 2012
      • 0 Attachment
        Christian Brabandt wrote:

        > On Fr, 23 Nov 2012, Bram Moolenaar wrote:
        >
        > > Christian Brabandt wrote:
        > >
        > > > On Do, 22 Nov 2012, Bram Moolenaar wrote:
        > > >
        > > > >
        > > > > Andy Wokula wrote:
        > > > >
        > > > > > " Vim Parsing Bug
        > > > > >
        > > > > > func! Add2(x1, x2)
        > > > > > return a:x1 + a:x2
        > > > > > endfunc
        > > > > >
        > > > > > :echo function('Add2')(2,3)
        > > > > > " 5 (ok)
        > > > > >
        > > > > > " Bug:
        > > > > > :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
        > > > > > :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
        > > > > >
        > > > > > " Error detected while processing D1223.vim:
        > > > > > " line 17:
        > > > > > " E110: Missing ')'
        > > > > > " E15: Invalid expression: (2,3)
        > > > > > " line 18:
        > > > > > " E109: Missing ':' after '?'
        > > > > > " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
        > > > > >
        > > > > >
        > > > > > Adding parentheses 1 ? (...) : (...) doesn't help.
        > > > >
        > > > > Strange. I'll add it to the todo list.
        > > >
        > > > Problem is, in expr1 ? expr2 : expr3
        > > > Vim explicitly resets evaluate in the false case which leads to being
        > > > rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
        > > > the subscript anymore.
        > > >
        > > > Here is a patch:
        > > >
        > > > diff --git a/src/eval.c b/src/eval.c
        > > > --- a/src/eval.c
        > > > +++ b/src/eval.c
        > > > @@ -19574,7 +19574,7 @@
        > > > while (ret == OK
        > > > && (**arg == '['
        > > > || (**arg == '.' && rettv->v_type == VAR_DICT)
        > > > - || (**arg == '(' && rettv->v_type == VAR_FUNC))
        > > > + || (**arg == '(' && (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_UNKNOWN)))
        > > > && !vim_iswhite(*(*arg - 1)))
        > > > {
        > > > if (**arg == '(')
        > >
        > > Thanks for the quick fix.
        > >
        > > Now, how about a test?
        >
        > Well, I am not sure, what caused the segfault for Andy. But I have been
        > checking with him privately, that this patch works and added some tests.
        > So here we go, a different patch, including a test.

        Thanks!

        --
        hundred-and-one symptoms of being an internet addict:
        62. If your doorbell rings, you think that new mail has arrived. And then
        you're disappointed that it's only someone at the door.

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

        --
        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
      • Andy Wokula
        ... (obsolete patch) ... So far, this latest patch works ok for me. -- Andy -- You received this message from the vim_dev maillist. Do not top-post! Type
        Message 3 of 9 , Jan 4, 2013
        • 0 Attachment
          Am 23.11.2012 22:09, schrieb Bram Moolenaar:
          >
          > Christian Brabandt wrote:
          >
          >> On Fr, 23 Nov 2012, Bram Moolenaar wrote:
          >>
          >>> Christian Brabandt wrote:
          >>>
          >>>> On Do, 22 Nov 2012, Bram Moolenaar wrote:
          >>>>
          >>>>>
          >>>>> Andy Wokula wrote:
          >>>>>
          >>>>>> " Vim Parsing Bug
          >>>>>>
          >>>>>> func! Add2(x1, x2)
          >>>>>> return a:x1 + a:x2
          >>>>>> endfunc
          >>>>>>
          >>>>>> :echo function('Add2')(2,3)
          >>>>>> " 5 (ok)
          >>>>>>
          >>>>>> " Bug:
          >>>>>> :echo 1 ? function('Add2')(1,2) : function('Add2')(2,3)
          >>>>>> :echo 0 ? function('Add2')(1,2) : function('Add2')(2,3)
          >>>>>>
          >>>>>> " Error detected while processing D1223.vim:
          >>>>>> " line 17:
          >>>>>> " E110: Missing ')'
          >>>>>> " E15: Invalid expression: (2,3)
          >>>>>> " line 18:
          >>>>>> " E109: Missing ':' after '?'
          >>>>>> " E15: Invalid expression: 0 ? function('Add2')(1,2) : function('Add2')(2,3)
          >>>>>>
          >>>>>>
          >>>>>> Adding parentheses 1 ? (...) : (...) doesn't help.
          >>>>>
          >>>>> Strange. I'll add it to the todo list.
          >>>>
          >>>> Problem is, in expr1 ? expr2 : expr3
          >>>> Vim explicitly resets evaluate in the false case which leads to being
          >>>> rettv.v_type being VAR_UNKNOWN and then handle_subscript doesn't handle
          >>>> the subscript anymore.
          >>>>
          >>>> Here is a patch:
          (obsolete patch)
          >>>
          >>> Thanks for the quick fix.
          >>>
          >>> Now, how about a test?
          >>
          >> Well, I am not sure, what caused the segfault for Andy. But I have been
          >> checking with him privately, that this patch works and added some tests.
          >> So here we go, a different patch, including a test.
          >
          > Thanks!

          So far, this latest patch works ok for me.

          --
          Andy

          --
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.