[vim/vim] Vim9: cannot compile ":if" when preceded by ":legacy" (#8309)

8 views
Skip to first unread message

lacygoill

unread,
Jun 2, 2021, 10:02:39 AM6/2/21
to vim/vim, Subscribed

Describe the bug

In Vim9 script, we cannot compile an :if command when it's preceded by the :legacy modifier.

To Reproduce

Run this shell command:

vim -Nu NONE -S <(cat <<'EOF'
    vim9script
    def Func()
        legacy if 1
            echo 'no error'
        endif
    enddef
    defcompile
EOF
)

E580 is raised:

E580: :endif without :if

Expected behavior

No error is raised.

Environment

  • Vim version: 8.2 Included patches: 1-2925
  • OS: Ubuntu 20.04.2 LTS
  • Terminal: XTerm(353)

Additional context

At the script level, the code works fine:

vim9script
legacy if 1
    echo 'no error'
endif
no error

Which seems inconsistent.


No issue with other modifiers; like :silent for example:

vim9script
def Func()
    silent if !!execute('ls', '')
    endif
enddef
defcompile

Again, this seems inconsistent. If Vim can compile :silent if, why not :legacy if?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
Jun 2, 2021, 10:42:39 AM6/2/21
to vim...@googlegroups.com, lacygoill

> **Describe the bug**
>
> In Vim9 script, we cannot compile an `:if` command when it's preceded by the `:legacy` modifier.
>
> **To Reproduce**
>
> Run this shell command:
>
> vim -Nu NONE -S <(cat <<'EOF'
> vim9script
> def Func()
> legacy if 1
> echo 'no error'
> endif
> enddef
> defcompile
> EOF
> )
>
> `E580` is raised:
>
> E580: :endif without :if
>
> **Expected behavior**
>
> No error is raised.

Using :if, :for, :while, :try, etc. in a :def function with :legacy is
not going to work, because it depends on interpreting lines at runtime.
There could be a better error message for this.


--
If an elephant is left tied to a parking meter, the parking fee has to be paid
just as it would for a vehicle.
[real standing law in Florida, United States of America]

/// 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 ///

Bram Moolenaar

unread,
Jun 2, 2021, 10:48:38 AM6/2/21
to vim/vim, Subscribed

Closed #8309 via c3cb1c9.

Reply all
Reply to author
Forward
0 new messages