Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Vim allows adding and removing items from a const list #6719

@bfrg

Description

@bfrg

Describe the bug
Vim doesn't throw any errors when a const list is filtered with filter().

According to :h :const, const is like lockvar 1 {name}. Further down the help page it says that when locking a list with lockvar 1 items cannot be added or removed from the list.

To Reproduce

  1. Run vim --clean -S test.vim
function Test() abort
    const test = range(10)
    return filter(test, 'v:val % 2 == 0')
endfunction
echo Test()
  1. Result:
[0, 2, 4, 6, 8]

Expected behavior
I would have expected Vim to throw an error when items are being removed from a const list.

Environment
Vim version 8.2.1464

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions