Hi,

On Mon, Jul 26, 2021 at 8:11 AM lacygoill <[email protected]> wrote:

> *Describe the bug*
>
> In Vim9 script, passing the output of a funcref to get() might give an
> error in compiled code, but not at the script level, which is inconsistent.
>
> *To Reproduce*
>
> Run this shell command:
>
> vim -Nu NONE -S <(cat <<'EOF'
>     vim9script
>     var Getqflist: func = function('getqflist', [{id: 0}])
>     Getqflist()->get('id', 0)
> EOF
> )
>
> No error is given.
>
> Now, run the same code in a :def function:
>
> vim -Nu NONE -S <(cat <<'EOF'
>     vim9script
>     def Func(): number
>         var Getqflist: func = function('getqflist', [{id: 0}])
>         return Getqflist()->get('id', 0)
>     enddef
>     defcompile
> EOF
> )
>
> E1013 is given:
>
> E1013: Argument 1: type mismatch, expected list<any> but got unknown
>
> *Expected behavior*
>
> I think the second command should not give an error, to be consistent with
> what happens at the script level.
>
> IOW, if Vim doesn't know what the output of a function is, it should be
> treated as any. Does that make sense? Or would this lead to other issues?
>

The argument type check for the get() function already accepts the "any"
type
for the first argument. But in this case, the type is "unknown". To support
this,
we need to disable the type check for the first argument of get().

- Yegappan


> *Environment*
>
>    - Vim version: 8.2 Included patches: 1-3223
>    - OS: Ubuntu 20.04.2 LTS
>    - Terminal: XTerm(353)
>
> *Additional context*
>
> As a workaround, we can declare the return type of the funcref with
> list<any>:
>
> var Getqflist: func: list<any> = function('getqflist', [{id: 0}])
>                      ^-------^
>
> Test:
>
> vim9scriptdef Func(): number
>     var Getqflist: func: list<any> = function('getqflist', [{id: 0}])
>     return Getqflist()->get('id', 0)enddefdefcompileecho 'no error'
>
> no error
>
> ------------------------------
>
> *If* it is a regression, then it was introduced in 8.2.3221
> <https://github.com/vim/vim/releases/tag/v8.2.3221>.
>
> cc @yegappan <https://github.com/yegappan> via #8632
> <https://github.com/vim/vim/pull/8632>
>
>
>

-- 
-- 
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/CAAW7x7kpAo%3DqcE1rNBYn38zG9_qmWePb79jMDCf4zc3Mqm9-uw%40mail.gmail.com.

Raspunde prin e-mail lui