forked from aniani/vim
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 <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
20393bc02d
commit
b1d6db0be5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user