[vim/vim] behavior change in has_key() (#8546)

15 views
Skip to first unread message

Shane-XB-Qian

unread,
Jul 11, 2021, 9:30:48 AM7/11/21
to vim/vim, Subscribed

Describe the bug

vim9script

def Foo(n: number): void
  var bar = {'9': 'a', 'x': 'y'}
  echomsg bar->has_key(n)
enddef

Foo('9')

Expected behavior
looks n was treated as 'string' (when has_key) in the past implicitly, but recently change made it raise e1013 err.

Environment (please complete the following information):
v8.2.3140


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

Shane-XB-Qian

unread,
Jul 11, 2021, 9:43:35 AM7/11/21
to vim/vim, Subscribed

doc:

A key is always a String.  You can use a Number, it will be converted to a
String automatically.  Thus the String '4' and the number 4 will find the same
entry.

Shane-XB-Qian

unread,
Jul 11, 2021, 9:48:18 AM7/11/21
to vim/vim, Subscribed

btw:
we had such has_key() underscore naming, but mostly we should keep sth like haskey(), looks that's the right vim style... :-)

Bram Moolenaar

unread,
Jul 11, 2021, 10:08:57 AM7/11/21
to vim/vim, Subscribed

Foo() needs to be called with a number argument. That didn't change recently, so perhaps it's a mistake in your example.

The argument of has_key() was just changed in patch 8.2.3142, thus I think this problem was already fixed.

Bram Moolenaar

unread,
Jul 11, 2021, 10:08:59 AM7/11/21
to vim/vim, Subscribed

Closed #8546.

Shane-XB-Qian

unread,
Jul 11, 2021, 10:16:24 AM7/11/21
to vim/vim, Subscribed

ok, yes, 8.2.3142 fixed it about 1 hour ago. thx.

Bram Moolenaar

unread,
Jul 11, 2021, 10:34:10 AM7/11/21
to vim/vim, Subscribed

Hah, we are used to telling users reporting a problem that their version is half a year old and suggest trying a more recent one.
Now it's down to half an hour :-).

Shane-XB-Qian

unread,
Jul 11, 2021, 10:50:06 AM7/11/21
to vim/vim, Subscribed

um, i think the problem is not about 'age' or 'old', but the test case did not cover the cases, or sometimes we knew some changes obviously would break user cases.. or some changes changed the behavior too heavy (impacted lot), otherwise we would not release the change because the ci should had stopped the process already. :-)

Shane-XB-Qian

unread,
Jul 11, 2021, 11:02:06 AM7/11/21
to vim/vim, Subscribed

actually in the real life/work we faced the same issue -- so called 'agile', specially e.g only req 1 deployment into 1 data center,
actually i missed the 'version', not sure if someone had better solution/suggestion.

Shane-XB-Qian

unread,
Jul 11, 2021, 11:08:16 AM7/11/21
to vim/vim, Subscribed

btw: e1013 check type looks very strict, or something perhaps wrong,

vim9script

call sign_define([
	\ {'name': 'sign1',
	\  'text': '=>'},
	\ {'name': 'sign2',
	\  'text': '!!'}
	\ ])

def Bar(): void
	sign_define([{'name': 'sign1',
		\  'text': '=>'},
		\ {'name': 'sign2',
		\  'text': '!!'}
		\ ])
enddef

Bar()

if you like i can open a separate ticket, or here this type checking problem was not just about some specific funcs (e.g has_key(), sign_define()) ?

Yegappan Lakshmanan

unread,
Jul 11, 2021, 11:12:15 AM7/11/21
to vim_dev, reply+ACY5DGCJCSP7TFAWIC...@reply.github.com, vim/vim, Subscribed
Hi,

On Sun, Jul 11, 2021 at 8:08 AM Shane-XB-Qian <vim-dev...@256bit.org> wrote:

btw: e1013 check type looks very strict, or something perhaps wrong,

vim9script

call sign_define([
	\ {'name': 'sign1',
	\  'text': '=>'},
	\ {'name': 'sign2',
	\  'text': '!!'}
	\ ])

def Bar(): void
	sign_define([{'name': 'sign1',
		\  'text': '=>'},
		\ {'name': 'sign2',
		\  'text': '!!'}
		\ ])
enddef

Bar()

if you like i can open a separate ticket, or here this type checking problem was not just about some specific funcs (e.g has_key(), sign_define()) ?


I have created the PR 8545 to address this issue.

Regards,
Yegappan

vim-dev ML

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

Hi,

On Sun, Jul 11, 2021 at 8:08 AM Shane-XB-Qian ***@***.***>

wrote:

> btw: e1013 check type looks very strict, or something perhaps wrong,
>
> vim9script
> call sign_define([
> \ {'name': 'sign1',
> \ 'text': '=>'},
> \ {'name': 'sign2',
> \ 'text': '!!'}
> \ ])
> def Bar(): void
> sign_define([{'name': 'sign1',
> \ 'text': '=>'},
> \ {'name': 'sign2',
> \ 'text': '!!'}
> \ ])enddef
> Bar()
>
> if you like i can open a separate ticket, or here this type checking
> problem was not just about some specific funcs (e.g has_key(),
> sign_define()) ?
>
>
> I have created the PR 8545 to address this issue.

Regards,
Yegappan

Shane-XB-Qian

unread,
Jul 11, 2021, 2:40:27 PM7/11/21
to vim/vim, vim-dev ML, Comment

and this one after 8545
var popupID = text->popup_atcursor({moved: 'any'})
expected string but got any


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Jul 11, 2021, 3:19:04 PM7/11/21
to vim_dev, reply+ACY5DGEIUK736PGZTR...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi,

On Sun, Jul 11, 2021 at 11:40 AM Shane-XB-Qian <vim-dev...@256bit.org> wrote:

and this one after 8545
var popupID = text->popup_atcursor({moved: 'any'})
expected string but got any



Thanks for reporting the issue. I have created PR #8551 to address
this issue. Let us know if you see Vim9 type check issues with any
other function.

Regards,
Yegappan

vim-dev ML

unread,
Jul 11, 2021, 3:19:22 PM7/11/21
to vim/vim, vim-dev ML, Your activity

Hi,

On Sun, Jul 11, 2021 at 11:40 AM Shane-XB-Qian ***@***.***>

wrote:

> and this one after 8545
> var popupID = text->popup_atcursor({moved: 'any'})
> expected string but got any
>
>
>
Thanks for reporting the issue. I have created PR #8551 to address
this issue. Let us know if you see Vim9 type check issues with any
other function.

Regards,
Yegappan

Shane-XB-Qian

unread,
Aug 26, 2021, 10:22:04 PM8/26/21
to vim/vim, vim-dev ML, Comment

@brammool @yegappan
bnr->setbufvar('&buflisted', true)
// "expected string but got bool"

doc:

In Vim9 script one can use "true" for v:true, "false" for v:false and "null"
for v:null. 


You are receiving this because you commented.


Reply to this email directly, view it on GitHub, or unsubscribe.

Triage notifications on the go with GitHub Mobile for iOS or Android.

Yegappan Lakshmanan

unread,
Aug 26, 2021, 11:57:32 PM8/26/21
to vim_dev, reply+ACY5DGCI6IN5GMKAXE...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi,

On Thu, Aug 26, 2021 at 7:22 PM Shane-XB-Qian <vim-dev...@256bit.org> wrote:

@brammool @yegappan
bnr->setbufvar('&buflisted', true)
// "expected string but got bool"


The new variable value is the base argument for the setbufvar()
method call and the buffer number is not the base argument.

From the help for setbufvar:

    Can also be used as a method, the base is passed as the
    third argument:
        GetValue()->setbufvar(buf, varname)

So you need to use

     true->setbufvar(bnr, '&buflisted')

- Yegappan

vim-dev ML

unread,
Aug 26, 2021, 11:57:49 PM8/26/21
to vim/vim, vim-dev ML, Your activity

Hi,

On Thu, Aug 26, 2021 at 7:22 PM Shane-XB-Qian ***@***.***>
wrote:

> @brammool <https://github.com/brammool> @yegappan
> <https://github.com/yegappan>

> bnr->setbufvar('&buflisted', true)
> // "expected string but got bool"
>

The new variable value is the base argument for the setbufvar()
method call and the buffer number is not the base argument.

From the help for setbufvar:

Can also be used as a method, the base is passed as the
third argument:
GetValue()->setbufvar(buf, varname)

So you need to use

true->setbufvar(bnr, '&buflisted')

- Yegappan


> doc:
>
> In Vim9 script one can use "true" for v:true, "false" for v:false and "null"
> for v:null.
>
>
>


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

Shane-XB-Qian

unread,
Aug 27, 2021, 12:49:51 AM8/27/21
to vim/vim, vim-dev ML, Comment

the base is passed as the third argument

maybe not a good idea, since most the first argument was the base,
and actually this case is from your lsp plugin, so looks you were confused too...... :-)


You are receiving this because you commented.


Reply to this email directly, view it on GitHub, or unsubscribe.

Yegappan Lakshmanan

unread,
Aug 27, 2021, 1:06:29 AM8/27/21
to vim_dev, reply+ACY5DGHVTLM76DWPVM...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi,

On Thu, Aug 26, 2021 at 9:49 PM Shane-XB-Qian <vim-dev...@256bit.org> wrote:

the base is passed as the third argument

maybe not a good idea, since most the first argument was the base,
and actually this case is from your lsp plugin, so looks you were confused too...... :-)



I have pushed a fix for the LSP plugin.  It is good that the new Vim9 argument
type check caught this issue.

Regards,
Yegappan

vim-dev ML

unread,
Aug 27, 2021, 1:06:45 AM8/27/21
to vim/vim, vim-dev ML, Your activity

Hi,

On Thu, Aug 26, 2021 at 9:49 PM Shane-XB-Qian ***@***.***>

wrote:

> the base is passed as the third argument
>
> maybe not a good idea, since most the first argument was the base,
> and actually this case is from your lsp plugin, so looks you were confused
> too...... :-)
>
>
>
I have pushed a fix for the LSP plugin. It is good that the new Vim9
argument
type check caught this issue.

Regards,
Yegappan


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

Shane-XB-Qian

unread,
Aug 27, 2021, 1:49:08 AM8/27/21
to vim/vim, vim-dev ML, Comment

ok, but unfortunately, it's raising error when it's really called.
so 'used as a method' this is a case to prove this would code be confused.


You are receiving this because you commented.


Reply to this email directly, view it on GitHub, or unsubscribe.

Reply all
Reply to author
Forward
0 new messages