[vim/vim] Vim9: cannot pass list of numbers to "cursor()" (#8602)

8 views
Skip to first unread message

lacygoill

unread,
Jul 21, 2021, 11:40:23 AM7/21/21
to vim/vim, Subscribed

Describe the bug

In Vim9 script, we cannot pass a list of numbers to cursor().

To Reproduce

Run this shell command:

vim -Nu NONE +'vim9 cursor([1, 1])'

E1210 is raised:

E1210: Number required for argument 2

Expected behavior

No error is raised, because :help cursor() states that cursor() accepts a single list as only argument. And it is allowed for the latter to only contain 2 numbers:

When there is one argument {list} this is used as a |List|
with two, three or four item:
[{lnum}, {col}]

Environment

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

Additional context

Regression introduced in 8.2.3188.


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,
Jul 21, 2021, 11:47:22 AM7/21/21
to vim_dev, reply+ACY5DGDJN7AFYLIZ3G...@reply.github.com, vim/vim, Subscribed
Hi,

On Wed, Jul 21, 2021 at 8:40 AM lacygoill <vim-dev...@256bit.org> wrote:

Describe the bug

In Vim9 script, we cannot pass a list of numbers to cursor().

To Reproduce

Run this shell command:

vim -Nu NONE +'vim9 cursor([1, 1])'

E1210 is raised:

E1210: Number required for argument 2

Expected behavior

No error is raised, because :help cursor() states that cursor() accepts a single list as only argument. And it is allowed for the latter to only contain 2 numbers:

When there is one argument {list} this is used as a |List|
with two, three or four item:
[{lnum}, {col}]

Environment

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

Additional context

Regression introduced in 8.2.3188.



Thanks for reporting the issue. I have updated PR #8598 with
a fix for this.

Regards,
Yegappan
 

vim-dev ML

unread,
Jul 21, 2021, 11:47:36 AM7/21/21
to vim/vim, vim-dev ML, Your activity

Hi,

On Wed, Jul 21, 2021 at 8:40 AM lacygoill ***@***.***> wrote:

> *Describe the bug*

>
> In Vim9 script, we cannot pass a list of numbers to cursor().
>
> *To Reproduce*

>
> Run this shell command:
>
> vim -Nu NONE +'vim9 cursor([1, 1])'
>
> E1210 is raised:
>
> E1210: Number required for argument 2
>
> *Expected behavior*

>
> No error is raised, because :help cursor() states that cursor() accepts a
> single list as only argument. And it is allowed for the latter to only
> contain 2 numbers:
>
> When there is one argument {list} this is used as a |List|
> with two, three or four item:
> [{lnum}, {col}]
>
> *Environment*
>
> - Vim version: 8.2 Included patches: 1-3189
> - OS: Ubuntu 20.04.2 LTS
> - Terminal: XTerm(353)
>
> *Additional context*

>
> Regression introduced in 8.2.3188.
>
>
>
Thanks for reporting the issue. I have updated PR #8598 with
a fix for this.

Regards,
Yegappan

Bram Moolenaar

unread,
Jul 21, 2021, 1:10:54 PM7/21/21
to vim/vim, vim-dev ML, Comment

Fixed in 8.2.3194


You are receiving this because you commented.

Bram Moolenaar

unread,
Jul 21, 2021, 1:10:55 PM7/21/21
to vim/vim, vim-dev ML, Comment

Closed #8602.


You are receiving this because you commented.

lacygoill

unread,
Jul 22, 2021, 1:02:00 PM7/22/21
to vim/vim, vim-dev ML, Comment

This gives an error:

vim9script
def Func()
    var prop: dict<any> = prop_find({type: 'TypeName'})
    cursor(prop.lnum, prop.col)
enddef
defcompile
E1013: Argument 1: type mismatch, expected number but got any

Is it working as intended?


You are receiving this because you commented.

lacygoill

unread,
Jul 22, 2021, 2:38:56 PM7/22/21
to vim/vim, vim-dev ML, Comment

Is it working as intended?

There are 3 possibilities.

  1. Vim gets smarter, and correctly infers that prop.lnum (as well as prop.col) is actually a number, even though it's included inside a dictionary of mixed values. I doubt that's possible without a lot of work though.

  2. Vim accepts any at compile time, and waits until runtime to check whether prop.lnum is actually a number (it is). Pro: no error. Con: we might miss some errors at compile time.

  3. Vim keeps rejecting any at compile time, and we need extra variables to feed the correct types to the compiler:

vim9script
def Func()
    var prop: dict<any> = prop_find({type: 'TypeName'
})
    var lnum: number = prop.lnum
    var col: number = prop.col
    cursor(lnum, col)
enddef
defcompile


You are receiving this because you commented.

lacygoill

unread,
Jul 22, 2021, 2:39:10 PM7/22/21
to vim/vim, vim-dev ML, Comment

Something else looks weird. This gives an error:

vim9script
def Func()
    var prop: dict<any> = prop_find({type: 'TypeName'
})
    var lnum = prop.lnum
    var col = prop.col
    cursor(lnum, col)
enddef
defcompile
E1013: Argument 1: type mismatch, expected number but got any

But not this:

vim9script
def Func()
    var prop: dict<any> = prop_find({type: 'TypeName'})
    var lnum: number =
 prop.lnum
    var col = prop.col
    cursor(lnum, col)
enddef
defcompile

Why? To be consistent, a similar error should be given for the second argument of cursor():

E1013: Argument 2: type mismatch, expected number but got any


You are receiving this because you commented.

Bram Moolenaar

unread,
Jul 23, 2021, 3:53:28 PM7/23/21
to vim/vim, vim-dev ML, Comment

It looks like the recent patches have solved this problem.


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages