Patch 9.0.1207

2 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 16, 2023, 11:40:12 AM1/16/23
to vim...@googlegroups.com

Patch 9.0.1207
Problem: Error when object type is expected but getting "any".
Solution: When actual type is "any" use a runtime type check.
(closes #11826)
Files: src/vim9type.c, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1206/src/vim9type.c 2023-01-15 18:17:08.785655216 +0000
--- src/vim9type.c 2023-01-16 16:33:04.227161443 +0000
***************
*** 878,883 ****
--- 878,888 ----
}
else if (expected->tt_type == VAR_OBJECT)
{
+ if (actual->tt_type == VAR_ANY)
+ return MAYBE; // use runtime type check
+ if (actual->tt_type != VAR_OBJECT)
+ return FAIL; // don't use tt_member
+
// check the class, base class or an implemented interface matches
class_T *cl;
for (cl = (class_T *)actual->tt_member; cl != NULL;
*** ../vim-9.0.1206/src/testdir/test_vim9_class.vim 2023-01-15 20:48:56.751583003 +0000
--- src/testdir/test_vim9_class.vim 2023-01-16 16:36:33.619074271 +0000
***************
*** 537,542 ****
--- 537,562 ----
assert_equal(5, o.GetMember())
END
v9.CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+
+ class Num
+ this.n: number = 0
+ endclass
+
+ def Ref(name: string): func(Num): Num
+ return (arg: Num): Num => {
+ return eval(name)(arg)
+ }
+ enddef
+
+ const Fn = Ref('Double')
+ var Double = (m: Num): Num => Num.new(m.n * 2)
+
+ echo Fn(Num.new(4))
+ END
+ v9.CheckScriptSuccess(lines)
enddef

def Test_class_member()
*** ../vim-9.0.1206/src/version.c 2023-01-16 13:01:24.373644105 +0000
--- src/version.c 2023-01-16 16:34:26.175123925 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1207,
/**/

--
Bypasses are devices that allow some people to dash from point A to
point B very fast while other people dash from point B to point A very
fast. People living at point C, being a point directly in between, are
often given to wonder what's so great about point A that so many people
from point B are so keen to get there and what's so great about point B
that so many people from point A are so keen to get there. They often
wish that people would just once and for all work out where the hell
they wanted to be.
-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages