Commit: patch 9.2.0973: Vim9: internal error when a class member is initialized with a closure
Christian Brabandt <[email protected]>
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <[email protected]> |
patch 9.2.0973: Vim9: internal error when a class member is initialized with a closure Commit: https://github.com/vim/vim/commit/7a35445af1cccbc9e25ae9d04291efa9072262b7 Author: Hirohito Higashi <[email protected]> Date: Tue Aug 18 20:31:12 2026 +0000 patch 9.2.0973: Vim9: internal error when a class member is initialized with a closure Problem: Initializing an object variable with a closure gives an internal error when the constructor is called without arguments (Mao-Yining). Solution: Do not use "any" as the type of an argument that was not set, and do not copy such an argument when the stack is copied for a closure (Hirohito Higashi). fixes: #21069 closes: #21081 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Hirohito Higashi <[email protected]> Signed-off-by: Christian Brabandt <[email protected]> diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 7d725e374..eb108bcb9 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -11887,4 +11887,21 @@ def Test_colon_whitespace() v9.CheckSourceSuccess(lines) enddef +" A closure in the initializer of an object variable, with the constructor +" called without arguments. +def Test_class_member_closure() + var lines =<< trim END + vim9script + class C + def F(): number + return 7 + enddef + var A = () => this.F() + endclass + var c = C.new() + assert_equal(7, c.A()) + 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 68353e0ba..76a606456 100644 --- a/src/version.c +++ b/src/version.c @@ -763,6 +763,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 973, /**/ 972, /**/ diff --git a/src/vim9execute.c b/src/vim9execute.c index b72e5700b..ddb6a5240 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -887,7 +887,8 @@ handle_closure_in_use(ectx_T *ectx, int free_arguments) *(stack + idx) = *tv; tv->v_type = VAR_UNKNOWN; } - else + else if (tv->v_type != VAR_UNKNOWN) + // Skip an argument that was not set, the stack was cleared. copy_tv(tv, stack + idx); } // Skip the stack frame. @@ -5264,9 +5265,12 @@ exec_instructions(ectx_T *ectx) size_t argidx = ufunc->uf_def_args.ga_len + iptr->isn_arg.jumparg.jump_arg_off + STACK_FRAME_SIZE; - type_T *tuple = ufunc->uf_arg_types[argidx]; + type_T *type = ufunc->uf_arg_types[argidx]; CLEAR_POINTER(tv); - tv->v_type = tuple->tt_type; + // "any" is not a type a value can have, leave the + // argument marked as not set. + if (type->tt_type != VAR_ANY) + tv->v_type = type->tt_type; } if (iptr->isn_type == ISN_JUMP_IF_ARG_SET ? arg_set : !arg_set) -- -- 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 [email protected]. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wwQgB-00Aj1t-Pa%40256bit.org.