vim9: E1013 error with recent changes

50 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Feb 7, 2021, 2:31:32 PM2/7/21
to vim_dev
Hi all,

The following sample code throws E1013 error in line 10 with Vim9:

============================================
vim9script

def Test()
var notif: dict<any> = {}
var docID: dict<any> = {}
var changeSet: list<dict<any>>

docID.uri = 'buf'
changeSet->add({text: ['one']})

notif.params = {}
notif.params->extend({textDocument: docID})
notif.params->extend({content: changeSet})
enddef

call Test()
============================================

This used to work till recently.

Regards,
Yegappan

Bram Moolenaar

unread,
Feb 7, 2021, 2:43:07 PM2/7/21
to vim...@googlegroups.com, Yegappan Lakshmanan
The error is:
1013: Argument 2: type mismatch, expected dict<dict<string>> but got dict<list<
dict<list<string>>>>

extend() is now checking that the dictionary does not change type.
In this case the dict members are of mixed type. Not sure if we should
somehow not check the type. You can use extendnew() at least.
Or use one extend() instead of two:

notif.params = {}
notif.params->extend({textDocument: docID, content: changeSet})


--
ARTHUR: Will you ask your master if he wants to join my court at Camelot?!
GUARD #1: But then of course African swallows are not migratory.
GUARD #2: Oh, yeah...
GUARD #1: So they couldn't bring a coconut back anyway...
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Yegappan Lakshmanan

unread,
Feb 7, 2021, 3:08:31 PM2/7/21
to Bram Moolenaar, vim_dev
Hi Bram,

On Sun, Feb 7, 2021 at 11:43 AM Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Yegappan wrote:
>
> > The following sample code throws E1013 error in line 10 with Vim9:
> >
> > ============================================
> > vim9script
> >
> > def Test()
> > var notif: dict<any> = {}
> > var docID: dict<any> = {}
> > var changeSet: list<dict<any>>
> >
> > docID.uri = 'buf'
> > changeSet->add({text: ['one']})
> >
> > notif.params = {}
> > notif.params->extend({textDocument: docID})
> > notif.params->extend({content: changeSet})
> > enddef
> >
> > call Test()
> > ============================================
> >
> > This used to work till recently.
>
> The error is:
> 1013: Argument 2: type mismatch, expected dict<dict<string>> but got dict<list<
> dict<list<string>>>>
>
> extend() is now checking that the dictionary does not change type.
>

The 'notif' variable is declared to be of type "dict<any>". So I thought
we could add elements of different types to this dict. But it looks like
the type of the first element that is added to the dict is used to check
the types of additional elements that are added later. I didn't expect
that.

Regards,
Yegappan

Bram Moolenaar

unread,
Feb 8, 2021, 4:07:52 AM2/8/21
to vim...@googlegroups.com, Yegappan Lakshmanan
If you add a dict to the "notif" dict, that dict also has a type that is
being checked. The "any" does not work for members inside "notif".

The problem is that if extend() is used for a declared type then we must
check it matches that type, but when the type wasn't declared we do not
need to do that, but there is no clue this is the case. There might be
a better way to do this somehow.

--
GUARD #2: Wait a minute -- supposing two swallows carried it together?
GUARD #1: No, they'd have to have it on a line.
GUARD #2: Well, simple! They'd just use a standard creeper!
GUARD #1: What, held under the dorsal guiding feathers?
GUARD #2: Well, why not?
Reply all
Reply to author
Forward
0 new messages