lockvar/unlockvar

13 views
Skip to first unread message

Ernie Rael

unread,
Sep 25, 2023, 11:26:43 AM9/25/23
to vim...@googlegroups.com
Hi all,

I'm wondering if I'm seeing an error

":help lockvar" seems to indicate that the following should work.
The goal is to get a writable variable "l1" that holds a locked list.

    vim9script
    var l0: list<list<number>> = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
    var l1 = l0
    lockvar! l1
    unlockvar 0 l1      # <<<<< expect "l1" writable, list still locked

    # Not modifying the value, but gets a value locked error
    l1 = null_list  # E741: Value is locked: l1

Can do it this way

    vim9script

    var l0: list<list<number>> = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
    lockvar! l0
    var l1 = l0

    #l1[0] = []          # fails as exepcted
    l1 = null_list      # works as expected

-ernie

Yegappan Lakshmanan

unread,
Sep 25, 2023, 7:44:29 PM9/25/23
to vim...@googlegroups.com
Hi,


On Mon, Sep 25, 2023 at 8:26 AM Ernie Rael <err...@raelity.com> wrote:
>
> Hi all,
>
> I'm wondering if I'm seeing an error
>
> ":help lockvar" seems to indicate that the following should work.
> The goal is to get a writable variable "l1" that holds a locked list.
>
>      vim9script
>      var l0: list<list<number>> = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
>      var l1 = l0
>      lockvar! l1
>      unlockvar 0 l1      # <<<<< expect "l1" writable, list still locked
>

I see the same problem in a legacy script and from the comments in
the var_check_permission function, it looks like this is done for
backward compatibility.

Regards,
Yegappan
Reply all
Reply to author
Forward
0 new messages