Mercurial > vim
comparison src/testdir/test_vim9_class.vim @ 33517:921673b465a6 v9.0.2007
patch 9.0.2007: Vim9: covariant parameter types allowed
Commit: https://github.com/vim/vim/commit/e4671890220ef3f2bca43fde6ffe5d3ef3ed0e42
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Mon Oct 9 18:01:06 2023 +0200
patch 9.0.2007: Vim9: covariant parameter types allowed
Problem: Vim9: covariant parameter types allowed when assigning
functions
Solution: Enforce invariant type check for arguments and return value
when assigning a funcref
closes: #13299
closes: #13305
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 09 Oct 2023 18:15:03 +0200 |
parents | f61713271934 |
children | f99f5a56ff27 |
comparison
equal
deleted
inserted
replaced
33516:4ee89f0a6df0 | 33517:921673b465a6 |
---|---|
7152 assert_equal(90, A.Foo()) | 7152 assert_equal(90, A.Foo()) |
7153 END | 7153 END |
7154 v9.CheckSourceSuccess(lines) | 7154 v9.CheckSourceSuccess(lines) |
7155 enddef | 7155 enddef |
7156 | 7156 |
7157 " Test for checking the argument types and the return type when assigning a | |
7158 " funcref to make sure the invariant class type is used. | |
7159 def Test_funcref_argtype_returntype_check() | |
7160 var lines =<< trim END | |
7161 vim9script | |
7162 class A | |
7163 endclass | |
7164 class B extends A | |
7165 endclass | |
7166 | |
7167 def Foo(p: B): B | |
7168 return B.new() | |
7169 enddef | |
7170 | |
7171 var Bar: func(A): A = Foo | |
7172 END | |
7173 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 11) | |
7174 | |
7175 lines =<< trim END | |
7176 vim9script | |
7177 class A | |
7178 endclass | |
7179 class B extends A | |
7180 endclass | |
7181 | |
7182 def Foo(p: B): B | |
7183 return B.new() | |
7184 enddef | |
7185 | |
7186 def Baz() | |
7187 var Bar: func(A): A = Foo | |
7188 enddef | |
7189 Baz() | |
7190 END | |
7191 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 1) | |
7192 enddef | |
7193 | |
7157 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker | 7194 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |