Problem seen with another example code in vim9.txt

11 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Mar 20, 2022, 7:06:52 PM3/20/22
to vim_dev
Hi,

I see a problem with another example code in vim9.txt:

-----------------------------------------------------------------------
command -range Rename {
var save = @a
@a = 'some expression'
echo 'do something with ' .. @a
@a = save
}
-----------------------------------------------------------------------

After sourcing the above code, If I invoke the "Rename"
command more than once, I see the "E1041: Redefining
script item save" error:

- Yegappan

Bram Moolenaar

unread,
Mar 21, 2022, 9:11:25 AM3/21/22
to vim...@googlegroups.com, Yegappan Lakshmanan
Interestingly, this only happens using a legacy script.
Putting "vim9script" above it avoids the problem.

This must be because in Vim9 script variables are kept local to a block.
In legacy script a variable declared in a block can be used after that
block. On the other hand, the {} block is Vim9 script, thus it's like
the variable is not really defined at the script level.

I think this needs to be fixed, the example should work.

--
You got to work at a mill? Lucky! I got sent back to work in the
acid-mines for my daily crust of stale bread... which not even the
birds would eat.

/// 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 ///
Reply all
Reply to author
Forward
0 new messages