patch 9.1.1332: Vim9: segfault when using super within a lambda
Commit:
https://github.com/vim/vim/commit/69e6ab6db3709d137508fec34d1fcadc69cef375
Author: Yegappan Lakshmanan <[email protected]>
Date: Tue Apr 22 19:55:38 2025 +0200
patch 9.1.1332: Vim9: segfault when using super within a lambda
Problem: Vim9: segfault when using super within a lambda
(lifepillar)
Solution: inherit the class from the current function
(Yegappan Lakshmanan)
fixes: #17166
closes: #17185
Signed-off-by: Yegappan Lakshmanan <[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 4aa9bb3b3..e854571e5 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -12544,6 +12544,35 @@ def Test_super_keyword()
assert_equal('A.Foo B.Foo', b.Bar())
END
v9.CheckSourceSuccess(lines)
+
+ # Test for using super in a lambda function to invoke a base class method
from
+ # the new() method.
+ lines =<< trim END
+ vim9script
+
+ def G(F: func): string
+ return F()
+ enddef
+
+ class Base
+ def F(): string
+ return 'Base.F()'
+ enddef
+ endclass
+
+ class Foo extends Base
+ var s: string = 'x'
+ def new()
+ this.s = G((): string => {
+ return super.F()
+ })
+ enddef
+ endclass
+
+ var f = Foo.new()
+ assert_equal('Base.F()', f.s)
+ END
+ v9.CheckSourceSuccess(lines)
enddef
" Test for using a list of objects
diff --git a/src/version.c b/src/version.c
index 2209282f8..35e71ca71 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1332,
/**/
1331,
/**/
diff --git a/src/vim9expr.c b/src/vim9expr.c
index 40c5fcc72..d169ed75a 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -1647,6 +1647,11 @@ compile_lambda(char_u **arg, cctx_T *cctx)
++ufunc->uf_refcount;
clear_tv(&rettv);
+ if (cctx->ctx_ufunc != NULL)
+ // This lambda might be defined in a class method. Inherit the class
+ // from the current function.
+ ufunc->uf_defclass = cctx->ctx_ufunc->uf_defclass;
+
// Compile it here to get the return type. The return type is optional,
// when it's missing use t_unknown. This is recognized in
// compile_return().
--
--
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/E1u7Hum-001NkF-6V%40256bit.org.