diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-08-27 19:08:40 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-08-27 19:08:40 +0200 |
commit | b49ad28d731551ddbd5cc57f9c77d0df085ae845 (patch) | |
tree | 646c8f3584f76f0a4799a884c8c2e4f0581ee706 /src | |
parent | 6a3897232aecd3e8b9e8b23955e55c1993e5baec (diff) |
patch 9.0.1801: Vim9 instanceof() fails in a def funcv9.0.1801
Problem: Vim9 instanceof() fails in a def func
Solution: allow Objects in compile time check
closes: #12907
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/evalfunc.c | 6 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 22 | ||||
-rw-r--r-- | src/testdir/test_vim9_class.vim | 14 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 43 insertions, 1 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index bdfd6325fe..2cd1985a06 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -282,7 +282,11 @@ arg_number(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) static int arg_object(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) { - return check_arg_type(&t_object, type, context); + if (type->tt_type == VAR_OBJECT + || type_any_or_unknown(type)) + return OK; + arg_type_mismatch(&t_object, type, context->arg_idx + 1); + return FAIL; } /* diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index da8bc4299f..dc5f3362b3 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -2317,6 +2317,28 @@ def Test_instanceof() instanceof(Foo.new(), 123) END v9.CheckScriptFailure(lines, 'E693: List or Class required for argument 2') + + lines =<< trim END + vim9script + class Foo + endclass + def Bar() + instanceof('hello', Foo) + enddef + Bar() + END + v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected object<Unknown> but got string') + + lines =<< trim END + vim9script + class Foo + endclass + def Bar() + instanceof(Foo.new(), 123) + enddef + Bar() + END + v9.CheckScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected class<Unknown> but got number') enddef def Test_invert() diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 2c6a501b45..5f5528aebd 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -2436,6 +2436,20 @@ def Test_instanceof() assert_true(instanceof(b3, Mix1)) assert_false(instanceof(b3, [])) assert_true(instanceof(b3, [Base1, Base2, Intf1])) + + def Foo() + var a1 = Base1.new() + var a2 = Base2.new() + var a3 = Base3.new() + + assert_true(instanceof(a1, Base1)) + assert_true(instanceof(a2, Base1)) + assert_false(instanceof(a1, Base2)) + assert_true(instanceof(a3, Mix1)) + assert_false(instanceof(a3, [])) + assert_true(instanceof(a3, [Base1, Base2, Intf1])) + enddef + Foo() END v9.CheckScriptSuccess(lines) enddef diff --git a/src/version.c b/src/version.c index e686da6a5a..431ac38cbd 100644 --- a/src/version.c +++ b/src/version.c @@ -700,6 +700,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1801, +/**/ 1800, /**/ 1799, |