patch 9.1.1362: Vim9: type ignored when adding tuple to instance list var Commit: https://github.com/vim/vim/commit/41cddfa177096168ea7f7c4f2a2857c0d76ce5d8 Author: Yegappan Lakshmanan <yegap...@yahoo.com> Date: Sat May 3 19:11:45 2025 +0200
patch 9.1.1362: Vim9: type ignored when adding tuple to instance list var Problem: Vim9: type ignored when adding tuple to instance list var (Lifepillar) Solution: When getting the typval of class and object member variables, set the variable type (Yegappan Lakshmanan) fixes: #17236 closes: #17244 Signed-off-by: Yegappan Lakshmanan <yegap...@yahoo.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index e854571e5..3ba467b23 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -13084,4 +13084,73 @@ def Test_object_of_class_type() \ 'E1353: Class name not found: <number>']) enddef +" Test for the object and class member type +def Test_obj_class_member_type() + var lines =<< trim END + vim9script + class L + var l: list<number> + endclass + var obj_L = L.new([10, 20]) + assert_equal('list<number>', typename(obj_L.l)) + obj_L.l->add('a') + END + v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got string', 7) + + lines =<< trim END + vim9script + class T + var t: list<tuple<string>> + endclass + var obj_T = T.new([('a',), ('b',)]) + assert_equal('list<tuple<string>>', typename(obj_T.t)) + obj_T.t->add([('c', 10, true)]) + END + v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected tuple<string> but got list<tuple<string, number, bool>>', 7) + + lines =<< trim END + vim9script + class D + var d: dict<number> + endclass + var obj_D = D.new({a: 10, b: 20}) + assert_equal('dict<number>', typename(obj_D.d)) + obj_D.d->extend({c: 'C'}) + END + v9.CheckSourceFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string> in extend()', 7) + + lines =<< trim END + vim9script + class L + public static var l: list<number> + endclass + L.l = [10, 20] + assert_equal('list<number>', typename(L.l)) + L.l->add('a') + END + v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got string', 7) + + lines =<< trim END + vim9script + class T + public static var t: list<tuple<string>> + endclass + T.t = [('a',), ('b',)] + assert_equal('list<tuple<string>>', typename(T.t)) + T.t->add([('c', 10, true)]) + END + v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected tuple<string> but got list<tuple<string, number, bool>>', 7) + + lines =<< trim END + vim9script + class D + public static var d: dict<number> + endclass + D.d = {a: 10, b: 20} + assert_equal('dict<number>', typename(D.d)) + D.d->extend({c: 'C'}) + END + v9.CheckSourceFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string> in extend()', 7) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index 7d29d7020..4dc628f30 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1362, /**/ 1361, /**/ diff --git a/src/vim9class.c b/src/vim9class.c index 560c5ae28..a82cc1332 100644 --- a/src/vim9class.c +++ b/src/vim9class.c @@ -2928,11 +2928,13 @@ get_member_tv( object_T *obj = rettv->vval.v_object; typval_T *tv = (typval_T *)(obj + 1) + m_idx; copy_tv(tv, rettv); + set_tv_type(rettv, m->ocm_type); object_unref(obj); } else { copy_tv(&cl->class_members_tv[m_idx], rettv); + set_tv_type(rettv, m->ocm_type); class_unref(cl); } -- -- 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 visit https://groups.google.com/d/msgid/vim_dev/E1uBGgd-005oeq-Tp%40256bit.org.