Yegappan wrote:

> The following Vim9 function fails with "E1141: Indexable type required":
> 
> ======================================================
> vim9script
> 
> def g:Test()
>     var req = {}
>     req.params = {}
>     req.params.id = 10
>     echomsg req
> enddef
> call g:Test()
> ======================================================
> 
> The following legacy function works:
> 
> ======================================================
> func g:Test()
>     let req = {}
>     let req.params = {}
>     let req.params.id = 10
>     echomsg req
> endfunc
> call g:Test()
> ======================================================
> 
> Am I missing something here?

The type of "req" is not specified.  You initialize it with {}, which is
a dict with unknown member type.  You assign it a dict in the second
line, but that doesn't change the type.  In the third line you try to
access a member of an unknown.  At this point we expect a list or a
dict, with an unknown we don't know what to do.

We could assume the ".id" indicates it should be a dict and turn this
into a runtime type check, but that may hide problems.  Best is to
declare the type of "req":

        var req: dict<dict<number>> = {}

Then it works.

-- 
Q: What kind of stuff do you do?
A: I collect hobbies.

 /// Bram Moolenaar -- [email protected] -- 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    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202012071754.0B7HsfLl1418684%40masaka.moolenaar.net.

Raspunde prin e-mail lui