Hi,

On Sat, Sep 16, 2023 at 1:30 AM Lifepillar <vim-dev-git...@256bit.org>
wrote:

> Steps to reproduce
>
> Patch 9.0.1724 (“vim9class constructor argument type checking bug”) has
> introduced a regression in one of my Vim 9 libraries. I have a test suite
> that caught that
> <https://github.com/lifepillar/vim-devel/blob/main/start/librelalg/test/test_librelalg.vim>,
> but I was able to nail down the issue to the following self-contained
> script:
>
> vim9script
> def ListifyKeys(keys: any): list<list<string>>
>   if type(keys) == v:t_string
>     return [[keys]]
>   endif
>   return keysenddef
> class Rel
>   this.keys: list<list<string>>
>
>   def new(keys: any)
>     const keys_: list<list<string>> = ListifyKeys(keys)
>   enddef
> endclass
> def Test()
>   var R = Rel.new('A')enddef
> Test()
>
> This fails with E1013: Argument 1: type mismatch, expected
> list<list<string>> but got string.
>
> Interestingly, if the this.keys attribute is removed, no error occurs.
> Expected behaviour
>
> I would expect the script above to run without errors. That was the case
> before patch 9.0.1724.
>
> The code currently checks for the type of arguments to the new()
constructor, even if the argument
name does not start with "this".  In the above example, if you rename the
"keys" argument to the
new() function, then you will not see this issue.

The following patch is needed to address this:

diff --git a/src/vim9instr.c b/src/vim9instr.c
index ccec0bcc3..7af478f71 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -1838,9 +1838,13 @@ generate_CALL(
                {
                    class_T *clp = mtype->tt_class;
                    char_u  *aname = ((char_u **)ufunc->uf_args.ga_data)[i];
-                   ocmember_T *m = object_member_lookup(clp, aname, 0,
NULL);
-                   if (m != NULL)
-                       expected = m->ocm_type;
+                   if (STRNCMP(aname, "this.", 5) == 0)
+                   {
+                       aname += 5;
+                       ocmember_T *m = object_member_lookup(clp, aname, 0,
NULL);
+                       if (m != NULL)
+                           expected = m->ocm_type;
+                   }
                }
            }
            else if (ufunc->uf_va_type == NULL

Some of the existing tests need to be adjusted for this change.

Regards,
Yegappan

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAAW7x7miWmq5tcFQL4YAS5rC_buoL74zXZX5DAt1Mxhg_Wsy%3DQ%40mail.gmail.com.

Raspunde prin e-mail lui