patch 9.1.1264: Vim9: error when comparing objects Commit: https://github.com/vim/vim/commit/b1d6db0be5cc4cd47c5cdac01e5d782a13243f31 Author: Yegappan Lakshmanan <yegap...@yahoo.com> Date: Mon Mar 31 20:35:44 2025 +0200
patch 9.1.1264: Vim9: error when comparing objects Problem: Vim9: error when comparing objects (lifepillar) Solution: When comparing object types, compare their classes (Yegappan Lakshmanan) fixes: #17014 closes: #17018 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 1e63f22df..30a03cf31 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -12481,4 +12481,44 @@ def Test_super_keyword() v9.CheckSourceSuccess(lines) enddef +" Test for using a list of objects +def Test_method_call_from_list_of_objects() + var lines =<< trim END + vim9script + + class C + def F(): string + return 'C.F' + enddef + endclass + + class D + var x: string + def new(this.x) + enddef + def F(): string + return 'D.F' + enddef + endclass + + var obj1 = C.new() + var obj2 = D.new('a') + + def CheckObjectList() + var items = [obj1, obj2] + assert_equal('list<any>', typename(items)) + assert_equal('C.F', items[0].F()) + assert_equal('D.F', items[1].F()) + enddef + + CheckObjectList() + + var items2 = [obj1, obj2] + assert_equal('list<any>', typename(items2)) + assert_equal('C.F', items2[0].F()) + assert_equal('D.F', items2[1].F()) + END + v9.CheckSourceSuccess(lines) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index 75cbd635d..67affb2e1 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 */ +/**/ + 1264, /**/ 1263, /**/ diff --git a/src/vim9type.c b/src/vim9type.c index abf4daf0f..03a391a17 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -1984,10 +1984,12 @@ equal_type(type_T *type1, type_T *type2, int flags) case VAR_JOB: case VAR_CHANNEL: case VAR_INSTR: - case VAR_CLASS: - case VAR_OBJECT: case VAR_TYPEALIAS: break; // not composite is always OK + case VAR_OBJECT: + case VAR_CLASS: + // Objects are considered equal if they are from the same class + return type1->tt_class == type2->tt_class; case VAR_LIST: case VAR_DICT: return equal_type(type1->tt_member, type2->tt_member, flags); -- -- 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/E1tzK8C-009s2V-IL%40256bit.org.