[vim/vim] Vim9: setqflist() and setloclist() do not take "true" as argument (#6882)

5 views
Skip to first unread message

lacygoill

unread,
Sep 5, 2020, 3:30:49 PM9/5/20
to vim/vim, Subscribed

Describe the bug

In Vim9 script, we cannot pass true as an argument to setqflist(), to specify that an entry is valid.

To Reproduce

Run this shell command:

vim -Nu NONE -S <(cat <<'EOF'
    vim9script
    let items = [#{filename: '/tmp/file', lnum: 1, valid: true}]
    let what = #{items: items}
    setqflist([], ' ', what)
EOF
)

And this shell command:

vim -Nu NONE -S <(cat <<'EOF'
    vim9script
    let items = [#{filename: '/tmp/file', lnum: 1, valid: false}]
    let what = #{items: items}
    setloclist(0, [], ' ', what)
EOF
)

E611 is raised in both cases:

E611: Using a Special as a Number

Expected behavior

No error is raised.

Environment

  • Vim version: 8.2 Included patches: 1-1613
  • OS: Ubuntu 16.04.7 LTS
  • Terminal: xterm(359)

Additional context

Regression introduced in 8.2.1465.


I don't know how to fix this issue; the code for the quickfix list is too complex for me. Here is a patch adding a test:

diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index b3b6b3225..c2c7416ec 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1609,6 +1609,18 @@ def Test_mapcheck()
   iunabbrev foo
 enddef
 
+def Test_setqflist()
+  let items = [#{filename: '/tmp/file', lnum: 1, valid: true}]
+  let what = #{items: items}
+  setqflist([], ' ', what)
+  assert_equal(1, getqflist()[0].valid)
+
+  items = [#{filename: '/tmp/file', lnum: 1, valid: false}]
+  what = #{items: items}
+  setloclist(0, [], ' ', what)
+  assert_equal(0, getloclist(0)[0].valid)
+enddef
+
 def Test_recursive_call()
   assert_equal(6765, Fibonacci(20))
 enddef


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

Yegappan Lakshmanan

unread,
Sep 5, 2020, 4:37:05 PM9/5/20
to vim_dev, reply+ACY5DGHXJV4DDP4R6D...@reply.github.com, vim/vim, Subscribed
Hi,

On Sat, Sep 5, 2020 at 12:30 PM lacygoill <vim-dev...@256bit.org> wrote:

Describe the bug

In Vim9 script, we cannot pass true as an argument to setqflist(), to specify that an entry is valid.

To Reproduce

Run this shell command:

vim -Nu NONE -S <(cat <<'EOF'
    vim9script
    let items = [#{filename: '/tmp/file', lnum: 1, valid: true}]
    let what = #{items: items}
    setqflist([], ' ', what)
EOF
)

The following change will address this issue:

==================================================
diff --git a/src/quickfix.c b/src/quickfix.c
index 09d5d8fa0..06178d37e 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -7072,7 +7072,7 @@ qf_add_entry_from_dict(
 
     // If the 'valid' field is present it overrules the detected value.
     if ((dict_find(d, (char_u *)"valid", -1)) != NULL)
-       valid = (int)dict_get_number(d, (char_u *)"valid");
+       valid = (int)dict_get_bool(d, (char_u *)"valid", valid);
 
     status =  qf_add_entry(qfl,
                        NULL,           // dir
==================================================

Regards,
Yegappan

vim-dev ML

unread,
Sep 5, 2020, 4:37:22 PM9/5/20
to vim/vim, vim-dev ML, Your activity

Hi,

On Sat, Sep 5, 2020 at 12:30 PM lacygoill <vim-dev...@256bit.org> wrote:

> *Describe the bug*

>
> In Vim9 script, we cannot pass true as an argument to setqflist(), to
> specify that an entry is valid.
>
> *To Reproduce*

>
> Run this shell command:
>
> vim -Nu NONE -S <(cat <<'EOF'
> vim9script
> let items = [#{filename: '/tmp/file', lnum: 1, valid: true}]
> let what = #{items: items}
> setqflist([], ' ', what)
> EOF
> )
>
>
The following change will address this issue:

==================================================
diff --git a/src/quickfix.c b/src/quickfix.c
index 09d5d8fa0..06178d37e 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -7072,7 +7072,7 @@ qf_add_entry_from_dict(

// If the 'valid' field is present it overrules the detected value.
if ((dict_find(d, (char_u *)"valid", -1)) != NULL)
- valid = (int)dict_get_number(d, (char_u *)"valid");
+ valid = (int)dict_get_bool(d, (char_u *)"valid", valid);

status = qf_add_entry(qfl,
NULL, // dir
==================================================

Regards,
Yegappan


> And this shell command:
>
> vim -Nu NONE -S <(cat <<'EOF'
> vim9script
> let items = [#{filename: '/tmp/file', lnum: 1, valid: false}]
> let what = #{items: items}
> setloclist(0, [], ' ', what)
> EOF
> )
>
> E611 is raised in both cases:
>
> E611: Using a Special as a Number
>
> *Expected behavior*
>
> No error is raised.
>
> *Environment*
>
> - Vim version: 8.2 Included patches: 1-1613
> - OS: Ubuntu 16.04.7 LTS
> - Terminal: xterm(359)
>
> *Additional context*
>
> Regression introduced in 8.2.1465
> <https://github.com/vim/vim/releases/tag/v8.2.1465>.
> ------------------------------

>
> I don't know how to fix this issue; the code for the quickfix list is too
> complex for me. Here is a patch adding a test:
>
> diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
> index b3b6b3225..c2c7416ec 100644--- a/src/testdir/test_vim9_func.vim+++ b/src/testdir/test_vim9_func.vim@@ -1609,6 +1609,18 @@ def Test_mapcheck()
> iunabbrev foo
> enddef
> +def Test_setqflist()+ let items = [#{filename: '/tmp/file', lnum: 1, valid: true}]+ let what = #{items: items}+ setqflist([], ' ', what)+ assert_equal(1, getqflist()[0].valid)++ items = [#{filename: '/tmp/file', lnum: 1, valid: false}]+ what = #{items: items}+ setloclist(0, [], ' ', what)+ assert_equal(0, getloclist(0)[0].valid)+enddef+

Bram Moolenaar

unread,
Sep 5, 2020, 4:38:09 PM9/5/20
to vim/vim, vim-dev ML, Comment

Closed #6882 via 401f0c0.


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages