changeset 26456:7eaf61a67d18 v8.2.3758

patch 8.2.3758: options that take a function insufficiently tested Commit: https://github.com/vim/vim/commit/2172bff36417ddd90653531edc65897411c83b3f Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Dec 8 10:46:21 2021 +0000 patch 8.2.3758: options that take a function insufficiently tested Problem: Options that take a function insufficiently tested. Solution: Add additional tests and enhance existing tests. (Yegappan Lakshmanan, closes #9298)
author Bram Moolenaar <Bram@vim.org>
date Wed, 08 Dec 2021 12:00:05 +0100
parents 1edd58619d1b
children 9b0883e8653c
files src/testdir/test_ins_complete.vim src/testdir/test_normal.vim src/testdir/test_tagfunc.vim src/version.c
diffstat 4 files changed, 553 insertions(+), 470 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -870,121 +870,114 @@ endfunc
 
 " Test for different ways of setting the 'completefunc' option
 func Test_completefunc_callback()
-  " Test for using a function()
-  func MycompleteFunc1(findstart, base)
-    call add(g:MycompleteFunc1_args, [a:findstart, a:base])
+  func MycompleteFunc1(val, findstart, base)
+    call add(g:MycompleteFunc1_args, [a:val, a:findstart, a:base])
     return a:findstart ? 0 : []
   endfunc
-  set completefunc=function('MycompleteFunc1')
+
+  " Test for using a function()
+  set completefunc=function('MycompleteFunc1',[10])
   new | only
   call setline(1, 'one')
   let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'one']], g:MycompleteFunc1_args)
+  call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args)
   bw!
 
   " Using a funcref variable to set 'completefunc'
-  let Fn = function('MycompleteFunc1')
+  let Fn = function('MycompleteFunc1', [11])
   let &completefunc = Fn
   new | only
   call setline(1, 'two')
   let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc1_args)
+  call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args)
   bw!
 
   " Using string(funcref_variable) to set 'completefunc'
-  let Fn = function('MycompleteFunc1')
+  let Fn = function('MycompleteFunc1', [12])
   let &completefunc = string(Fn)
   new | only
   call setline(1, 'two')
   let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc1_args)
+  call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args)
   bw!
 
   " Test for using a funcref()
-  func MycompleteFunc2(findstart, base)
-    call add(g:MycompleteFunc2_args, [a:findstart, a:base])
-    return a:findstart ? 0 : []
-  endfunc
-  set completefunc=funcref('MycompleteFunc2')
+  set completefunc=funcref('MycompleteFunc1',\ [13])
   new | only
   call setline(1, 'three')
-  let g:MycompleteFunc2_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'three']], g:MycompleteFunc2_args)
+  call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args)
   bw!
 
   " Using a funcref variable to set 'completefunc'
-  let Fn = funcref('MycompleteFunc2')
+  let Fn = funcref('MycompleteFunc1', [14])
   let &completefunc = Fn
   new | only
   call setline(1, 'four')
-  let g:MycompleteFunc2_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'four']], g:MycompleteFunc2_args)
+  call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args)
   bw!
 
   " Using a string(funcref_variable) to set 'completefunc'
-  let Fn = funcref('MycompleteFunc2')
+  let Fn = funcref('MycompleteFunc1', [15])
   let &completefunc = string(Fn)
   new | only
   call setline(1, 'four')
-  let g:MycompleteFunc2_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'four']], g:MycompleteFunc2_args)
+  call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args)
   bw!
 
   " Test for using a lambda function
-  func MycompleteFunc3(findstart, base)
-    call add(g:MycompleteFunc3_args, [a:findstart, a:base])
-    return a:findstart ? 0 : []
-  endfunc
-  set completefunc={a,\ b\ ->\ MycompleteFunc3(a,\ b)}
+  set completefunc={a,\ b\ ->\ MycompleteFunc1(16,\ a,\ b)}
   new | only
   call setline(1, 'five')
-  let g:MycompleteFunc3_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc3_args)
+  call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args)
   bw!
 
   " Set 'completefunc' to a lambda expression
-  let &completefunc = {a, b -> MycompleteFunc3(a, b)}
+  let &completefunc = {a, b -> MycompleteFunc1(17, a, b)}
   new | only
   call setline(1, 'six')
-  let g:MycompleteFunc3_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'six']], g:MycompleteFunc3_args)
+  call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args)
   bw!
 
   " Set 'completefunc' to string(lambda_expression)
-  let &completefunc = '{a, b -> MycompleteFunc3(a, b)}'
+  let &completefunc = '{a, b -> MycompleteFunc1(18, a, b)}'
   new | only
   call setline(1, 'six')
-  let g:MycompleteFunc3_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'six']], g:MycompleteFunc3_args)
+  call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args)
   bw!
 
   " Set 'completefunc' to a variable with a lambda expression
-  let Lambda = {a, b -> MycompleteFunc3(a, b)}
+  let Lambda = {a, b -> MycompleteFunc1(19, a, b)}
   let &completefunc = Lambda
   new | only
   call setline(1, 'seven')
-  let g:MycompleteFunc3_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'seven']], g:MycompleteFunc3_args)
+  call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args)
   bw!
 
   " Set 'completefunc' to a string(variable with a lambda expression)
-  let Lambda = {a, b -> MycompleteFunc3(a, b)}
+  let Lambda = {a, b -> MycompleteFunc1(20, a, b)}
   let &completefunc = string(Lambda)
   new | only
   call setline(1, 'seven')
-  let g:MycompleteFunc3_args = []
+  let g:MycompleteFunc1_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'seven']], g:MycompleteFunc3_args)
+  call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args)
   bw!
 
   " Test for using a lambda function with incorrect return value
@@ -1004,77 +997,18 @@ func Test_completefunc_callback()
   let &completefunc = {a -> 'abc'}
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
 
-  " Vim9 tests
-  let lines =<< trim END
-    vim9script
-
-    # Test for using function()
-    def MycompleteFunc1(findstart: number, base: string): any
-      add(g:MycompleteFunc1_args, [findstart, base])
-      return findstart ? 0 : []
-    enddef
-    set completefunc=function('MycompleteFunc1')
-    new | only
-    setline(1, 'one')
-    g:MycompleteFunc1_args = []
-    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'one']], g:MycompleteFunc1_args)
-    bw!
-
-    # Test for using a lambda
-    def LambdaComplete1(findstart: number, base: string): any
-      add(g:LambdaComplete1_args, [findstart, base])
-      return findstart ? 0 : []
-    enddef
-    &completefunc = (a, b) => LambdaComplete1(a, b)
-    new | only
-    setline(1, 'two')
-    g:LambdaComplete1_args = []
-    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'two']], g:LambdaComplete1_args)
-    bw!
-
-    # Test for using a string(lambda)
-    &completefunc = '(a, b) => LambdaComplete1(a, b)'
-    new | only
-    setline(1, 'two')
-    g:LambdaComplete1_args = []
-    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'two']], g:LambdaComplete1_args)
-    bw!
-
-    # Test for using a variable with a lambda expression
-    var Fn: func = (findstart, base) => {
-            add(g:LambdaComplete2_args, [findstart, base])
-            return findstart ? 0 : []
-        }
-    &completefunc = Fn
-    new | only
-    setline(1, 'three')
-    g:LambdaComplete2_args = []
-    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'three']], g:LambdaComplete2_args)
-    bw!
-
-    # Test for using a string(variable with a lambda expression)
-    &completefunc = string(Fn)
-    new | only
-    setline(1, 'three')
-    g:LambdaComplete2_args = []
-    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'three']], g:LambdaComplete2_args)
-    bw!
-  END
-  call CheckScriptSuccess(lines)
-
   " Using Vim9 lambda expression in legacy context should fail
-  set completefunc=(a,\ b)\ =>\ g:MycompleteFunc2(a,\ b)
+  set completefunc=(a,\ b)\ =>\ g:MycompleteFunc1(21,\ a,\ b)
   new | only
-  let g:MycompleteFunc2_args = []
+  let g:MycompleteFunc1_args = []
   call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
-  call assert_equal([], g:MycompleteFunc2_args)
+  call assert_equal([], g:MycompleteFunc1_args)
 
   " set 'completefunc' to a non-existing function
+  func MycompleteFunc2(findstart, base)
+    call add(g:MycompleteFunc2_args, [a:findstart, a:base])
+    return a:findstart ? 0 : []
+  endfunc
   set completefunc=MycompleteFunc2
   call setline(1, 'five')
   call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:')
@@ -1082,132 +1016,182 @@ func Test_completefunc_callback()
   let g:MycompleteFunc2_args = []
   call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
   call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args)
+  bw!
+
+  " Vim9 tests
+  let lines =<< trim END
+    vim9script
+
+    # Test for using function()
+    def Vim9CompleteFunc(val: number, findstart: number, base: string): any
+      add(g:Vim9completeFuncArgs, [val, findstart, base])
+      return findstart ? 0 : []
+    enddef
+    set completefunc=function('Vim9CompleteFunc',\ [60])
+    new | only
+    setline(1, 'one')
+    g:Vim9completeFuncArgs = []
+    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
+    assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs)
+    bw!
+
+    # Test for using a lambda
+    &completefunc = (a, b) => Vim9CompleteFunc(61, a, b)
+    new | only
+    setline(1, 'two')
+    g:Vim9completeFuncArgs = []
+    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
+    assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9completeFuncArgs)
+    bw!
+
+    # Test for using a string(lambda)
+    &completefunc = '(a, b) => Vim9CompleteFunc(62, a, b)'
+    new | only
+    setline(1, 'two')
+    g:Vim9completeFuncArgs = []
+    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
+    assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9completeFuncArgs)
+    bw!
+
+    # Test for using a variable with a lambda expression
+    var Fn: func = (a, b) => Vim9CompleteFunc(63, a, b)
+    &completefunc = Fn
+    new | only
+    setline(1, 'three')
+    g:Vim9completeFuncArgs = []
+    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
+    assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9completeFuncArgs)
+    bw!
+
+    # Test for using a string(variable with a lambda expression)
+    Fn = (a, b) => Vim9CompleteFunc(64, a, b)
+    &completefunc = string(Fn)
+    new | only
+    setline(1, 'three')
+    g:Vim9completeFuncArgs = []
+    feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
+    assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9completeFuncArgs)
+    bw!
+  END
+  call CheckScriptSuccess(lines)
 
   " cleanup
   delfunc MycompleteFunc1
   delfunc MycompleteFunc2
-  delfunc MycompleteFunc3
   set completefunc&
   %bw!
 endfunc
 
 " Test for different ways of setting the 'omnifunc' option
 func Test_omnifunc_callback()
-  " Test for using a function()
-  func MyomniFunc1(findstart, base)
-    call add(g:MyomniFunc1_args, [a:findstart, a:base])
+  func MyomniFunc1(val, findstart, base)
+    call add(g:MyomniFunc1_args, [a:val, a:findstart, a:base])
     return a:findstart ? 0 : []
   endfunc
-  set omnifunc=function('MyomniFunc1')
+
+  " Test for using a function()
+  set omnifunc=function('MyomniFunc1',[10])
   new | only
   call setline(1, 'one')
   let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'one']], g:MyomniFunc1_args)
+  call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args)
   bw!
 
   " Using a funcref variable to set 'omnifunc'
-  let Fn = function('MyomniFunc1')
+  let Fn = function('MyomniFunc1', [11])
   let &omnifunc = Fn
   new | only
   call setline(1, 'two')
   let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'two']], g:MyomniFunc1_args)
+  call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args)
   bw!
 
   " Using a string(funcref_variable) to set 'omnifunc'
-  let Fn = function('MyomniFunc1')
+  let Fn = function('MyomniFunc1', [12])
   let &omnifunc = string(Fn)
   new | only
   call setline(1, 'two')
   let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'two']], g:MyomniFunc1_args)
+  call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args)
   bw!
 
   " Test for using a funcref()
-  func MyomniFunc2(findstart, base)
-    call add(g:MyomniFunc2_args, [a:findstart, a:base])
-    return a:findstart ? 0 : []
-  endfunc
-  set omnifunc=funcref('MyomniFunc2')
+  set omnifunc=funcref('MyomniFunc1',\ [13])
   new | only
   call setline(1, 'three')
-  let g:MyomniFunc2_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args)
+  call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args)
   bw!
 
   " Using a funcref variable to set 'omnifunc'
-  let Fn = funcref('MyomniFunc2')
+  let Fn = funcref('MyomniFunc1', [14])
   let &omnifunc = Fn
   new | only
   call setline(1, 'four')
-  let g:MyomniFunc2_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'four']], g:MyomniFunc2_args)
+  call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args)
   bw!
 
   " Using a string(funcref_variable) to set 'omnifunc'
-  let Fn = funcref('MyomniFunc2')
+  let Fn = funcref('MyomniFunc1', [15])
   let &omnifunc = string(Fn)
   new | only
   call setline(1, 'four')
-  let g:MyomniFunc2_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'four']], g:MyomniFunc2_args)
+  call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args)
   bw!
 
   " Test for using a lambda function
-  func MyomniFunc3(findstart, base)
-    call add(g:MyomniFunc3_args, [a:findstart, a:base])
-    return a:findstart ? 0 : []
-  endfunc
-  set omnifunc={a,\ b\ ->\ MyomniFunc3(a,\ b)}
+  set omnifunc={a,\ b\ ->\ MyomniFunc1(16,\ a,\ b)}
   new | only
   call setline(1, 'five')
-  let g:MyomniFunc3_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'five']], g:MyomniFunc3_args)
+  call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args)
   bw!
 
   " Set 'omnifunc' to a lambda expression
-  let &omnifunc = {a, b -> MyomniFunc3(a, b)}
+  let &omnifunc = {a, b -> MyomniFunc1(17, a, b)}
   new | only
   call setline(1, 'six')
-  let g:MyomniFunc3_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'six']], g:MyomniFunc3_args)
+  call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args)
   bw!
 
   " Set 'omnifunc' to a string(lambda_expression)
-  let &omnifunc = '{a, b -> MyomniFunc3(a, b)}'
+  let &omnifunc = '{a, b -> MyomniFunc1(18, a, b)}'
   new | only
   call setline(1, 'six')
-  let g:MyomniFunc3_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'six']], g:MyomniFunc3_args)
+  call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args)
   bw!
 
   " Set 'omnifunc' to a variable with a lambda expression
-  let Lambda = {a, b -> MyomniFunc3(a, b)}
+  let Lambda = {a, b -> MyomniFunc1(19, a, b)}
   let &omnifunc = Lambda
   new | only
   call setline(1, 'seven')
-  let g:MyomniFunc3_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'seven']], g:MyomniFunc3_args)
+  call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args)
   bw!
 
   " Set 'omnifunc' to a string(variable with a lambda expression)
-  let Lambda = {a, b -> MyomniFunc3(a, b)}
+  let Lambda = {a, b -> MyomniFunc1(20, a, b)}
   let &omnifunc = string(Lambda)
   new | only
   call setline(1, 'seven')
-  let g:MyomniFunc3_args = []
+  let g:MyomniFunc1_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'seven']], g:MyomniFunc3_args)
+  call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args)
   bw!
 
   " Test for using a lambda function with incorrect return value
@@ -1227,74 +1211,18 @@ func Test_omnifunc_callback()
   let &omnifunc = {a -> 'abc'}
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
 
-  " Vim9 tests
-  let lines =<< trim END
-    vim9script
-
-    # Test for using function()
-    def MyomniFunc1(findstart: number, base: string): any
-      add(g:MyomniFunc1_args, [findstart, base])
-      return findstart ? 0 : []
-    enddef
-    set omnifunc=function('MyomniFunc1')
-    new | only
-    setline(1, 'one')
-    g:MyomniFunc1_args = []
-    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'one']], g:MyomniFunc1_args)
-    bw!
-
-    # Test for using a lambda
-    def MyomniFunc2(findstart: number, base: string): any
-      add(g:MyomniFunc2_args, [findstart, base])
-      return findstart ? 0 : []
-    enddef
-    &omnifunc = (a, b) => MyomniFunc2(a, b)
-    new | only
-    setline(1, 'two')
-    g:MyomniFunc2_args = []
-    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'two']], g:MyomniFunc2_args)
-    bw!
-
-    # Test for using a string(lambda)
-    &omnifunc = '(a, b) => MyomniFunc2(a, b)'
-    new | only
-    setline(1, 'two')
-    g:MyomniFunc2_args = []
-    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'two']], g:MyomniFunc2_args)
-    bw!
-
-    # Test for using a variable with a lambda expression
-    var Fn: func = (a, b) => MyomniFunc2(a, b)
-    &omnifunc = Fn
-    new | only
-    setline(1, 'three')
-    g:MyomniFunc2_args = []
-    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args)
-    bw!
-
-    # Test for using a string(variable with a lambda expression)
-    &omnifunc = string(Fn)
-    new | only
-    setline(1, 'three')
-    g:MyomniFunc2_args = []
-    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args)
-    bw!
-  END
-  call CheckScriptSuccess(lines)
-
   " Using Vim9 lambda expression in legacy context should fail
-  set omnifunc=(a,\ b)\ =>\ g:MyomniFunc2(a,\ b)
+  set omnifunc=(a,\ b)\ =>\ g:MyomniFunc1(21,\ a,\ b)
   new | only
-  let g:MyomniFunc2_args = []
+  let g:MyomniFunc1_args = []
   call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
-  call assert_equal([], g:MyomniFunc2_args)
+  call assert_equal([], g:MyomniFunc1_args)
 
   " set 'omnifunc' to a non-existing function
+  func MyomniFunc2(findstart, base)
+    call add(g:MyomniFunc2_args, [a:findstart, a:base])
+    return a:findstart ? 0 : []
+  endfunc
   set omnifunc=MyomniFunc2
   call setline(1, 'nine')
   call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:')
@@ -1302,132 +1230,182 @@ func Test_omnifunc_callback()
   let g:MyomniFunc2_args = []
   call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
   call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args)
+  bw!
+
+  " Vim9 tests
+  let lines =<< trim END
+    vim9script
+
+    # Test for using function()
+    def Vim9omniFunc(val: number, findstart: number, base: string): any
+      add(g:Vim9omniFunc_Args, [val, findstart, base])
+      return findstart ? 0 : []
+    enddef
+    set omnifunc=function('Vim9omniFunc',\ [60])
+    new | only
+    setline(1, 'one')
+    g:Vim9omniFunc_Args = []
+    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
+    assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args)
+    bw!
+
+    # Test for using a lambda
+    &omnifunc = (a, b) => Vim9omniFunc(61, a, b)
+    new | only
+    setline(1, 'two')
+    g:Vim9omniFunc_Args = []
+    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
+    assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9omniFunc_Args)
+    bw!
+
+    # Test for using a string(lambda)
+    &omnifunc = '(a, b) => Vim9omniFunc(62, a, b)'
+    new | only
+    setline(1, 'two')
+    g:Vim9omniFunc_Args = []
+    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
+    assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9omniFunc_Args)
+    bw!
+
+    # Test for using a variable with a lambda expression
+    var Fn: func = (a, b) => Vim9omniFunc(63, a, b)
+    &omnifunc = Fn
+    new | only
+    setline(1, 'three')
+    g:Vim9omniFunc_Args = []
+    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
+    assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9omniFunc_Args)
+    bw!
+
+    # Test for using a string(variable with a lambda expression)
+    Fn = (a, b) => Vim9omniFunc(64, a, b)
+    &omnifunc = string(Fn)
+    new | only
+    setline(1, 'three')
+    g:Vim9omniFunc_Args = []
+    feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
+    assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9omniFunc_Args)
+    bw!
+  END
+  call CheckScriptSuccess(lines)
 
   " cleanup
   delfunc MyomniFunc1
   delfunc MyomniFunc2
-  delfunc MyomniFunc3
   set omnifunc&
   %bw!
 endfunc
 
 " Test for different ways of setting the 'thesaurusfunc' option
 func Test_thesaurusfunc_callback()
-  " Test for using a function()
-  func MytsrFunc1(findstart, base)
-    call add(g:MytsrFunc1_args, [a:findstart, a:base])
+  func MytsrFunc1(val, findstart, base)
+    call add(g:MytsrFunc1_args, [a:val, a:findstart, a:base])
     return a:findstart ? 0 : []
   endfunc
-  set thesaurusfunc=function('MytsrFunc1')
+
+  " Test for using a function()
+  set thesaurusfunc=function('MytsrFunc1',[10])
   new | only
   call setline(1, 'one')
   let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'one']], g:MytsrFunc1_args)
+  call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args)
   bw!
 
   " Using a funcref variable to set 'thesaurusfunc'
-  let Fn = function('MytsrFunc1')
+  let Fn = function('MytsrFunc1', [11])
   let &thesaurusfunc = Fn
   new | only
   call setline(1, 'two')
   let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'two']], g:MytsrFunc1_args)
+  call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args)
   bw!
 
   " Using a string(funcref_variable) to set 'thesaurusfunc'
-  let Fn = function('MytsrFunc1')
+  let Fn = function('MytsrFunc1', [12])
   let &thesaurusfunc = string(Fn)
   new | only
   call setline(1, 'two')
   let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'two']], g:MytsrFunc1_args)
+  call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args)
   bw!
 
   " Test for using a funcref()
-  func MytsrFunc2(findstart, base)
-    call add(g:MytsrFunc2_args, [a:findstart, a:base])
-    return a:findstart ? 0 : []
-  endfunc
-  set thesaurusfunc=funcref('MytsrFunc2')
+  set thesaurusfunc=funcref('MytsrFunc1',[13])
   new | only
   call setline(1, 'three')
-  let g:MytsrFunc2_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args)
+  call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args)
   bw!
 
   " Using a funcref variable to set 'thesaurusfunc'
-  let Fn = funcref('MytsrFunc2')
+  let Fn = funcref('MytsrFunc1', [14])
   let &thesaurusfunc = Fn
   new | only
   call setline(1, 'four')
-  let g:MytsrFunc2_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'four']], g:MytsrFunc2_args)
+  call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args)
   bw!
 
   " Using a string(funcref_variable) to set 'thesaurusfunc'
-  let Fn = funcref('MytsrFunc2')
+  let Fn = funcref('MytsrFunc1', [15])
   let &thesaurusfunc = string(Fn)
   new | only
   call setline(1, 'four')
-  let g:MytsrFunc2_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'four']], g:MytsrFunc2_args)
+  call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args)
   bw!
 
   " Test for using a lambda function
-  func MytsrFunc3(findstart, base)
-    call add(g:MytsrFunc3_args, [a:findstart, a:base])
-    return a:findstart ? 0 : []
-  endfunc
-  set thesaurusfunc={a,\ b\ ->\ MytsrFunc3(a,\ b)}
+  set thesaurusfunc={a,\ b\ ->\ MytsrFunc1(16,\ a,\ b)}
   new | only
   call setline(1, 'five')
-  let g:MytsrFunc3_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'five']], g:MytsrFunc3_args)
+  call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args)
   bw!
 
   " Set 'thesaurusfunc' to a lambda expression
-  let &thesaurusfunc = {a, b -> MytsrFunc3(a, b)}
+  let &thesaurusfunc = {a, b -> MytsrFunc1(17, a, b)}
   new | only
   call setline(1, 'six')
-  let g:MytsrFunc3_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'six']], g:MytsrFunc3_args)
+  call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args)
   bw!
 
   " Set 'thesaurusfunc' to a string(lambda expression)
-  let &thesaurusfunc = '{a, b -> MytsrFunc3(a, b)}'
+  let &thesaurusfunc = '{a, b -> MytsrFunc1(18, a, b)}'
   new | only
   call setline(1, 'six')
-  let g:MytsrFunc3_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'six']], g:MytsrFunc3_args)
+  call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args)
   bw!
 
   " Set 'thesaurusfunc' to a variable with a lambda expression
-  let Lambda = {a, b -> MytsrFunc3(a, b)}
+  let Lambda = {a, b -> MytsrFunc1(19, a, b)}
   let &thesaurusfunc = Lambda
   new | only
   call setline(1, 'seven')
-  let g:MytsrFunc3_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'seven']], g:MytsrFunc3_args)
+  call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args)
   bw!
 
   " Set 'thesaurusfunc' to a string(variable with a lambda expression)
-  let Lambda = {a, b -> MytsrFunc3(a, b)}
+  let Lambda = {a, b -> MytsrFunc1(20, a, b)}
   let &thesaurusfunc = string(Lambda)
   new | only
   call setline(1, 'seven')
-  let g:MytsrFunc3_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-  call assert_equal([[1, ''], [0, 'seven']], g:MytsrFunc3_args)
+  call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args)
   bw!
 
   " Test for using a lambda function with incorrect return value
@@ -1447,102 +1425,42 @@ func Test_thesaurusfunc_callback()
   let &thesaurusfunc = {a -> 'abc'}
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
 
-  " Vim9 tests
-  let lines =<< trim END
-    vim9script
-
-    # Test for using function()
-    def MytsrFunc1(findstart: number, base: string): any
-      add(g:MytsrFunc1_args, [findstart, base])
-      return findstart ? 0 : []
-    enddef
-    set thesaurusfunc=function('MytsrFunc1')
-    new | only
-    setline(1, 'one')
-    g:MytsrFunc1_args = []
-    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'one']], g:MytsrFunc1_args)
-    bw!
-
-    # Test for using a lambda
-    def MytsrFunc2(findstart: number, base: string): any
-      add(g:MytsrFunc2_args, [findstart, base])
-      return findstart ? 0 : []
-    enddef
-    &thesaurusfunc = (a, b) => MytsrFunc2(a, b)
-    new | only
-    setline(1, 'two')
-    g:MytsrFunc2_args = []
-    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'two']], g:MytsrFunc2_args)
-    bw!
-
-    # Test for using a string(lambda)
-    &thesaurusfunc = '(a, b) => MytsrFunc2(a, b)'
-    new | only
-    setline(1, 'two')
-    g:MytsrFunc2_args = []
-    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'two']], g:MytsrFunc2_args)
-    bw!
-
-    # Test for using a variable with a lambda expression
-    var Fn: func = (a, b) => MytsrFunc2(a, b)
-    &thesaurusfunc = Fn
-    new | only
-    setline(1, 'three')
-    g:MytsrFunc2_args = []
-    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args)
-    bw!
-
-    # Test for using a string(variable with a lambda expression)
-    &thesaurusfunc = string(Fn)
-    new | only
-    setline(1, 'three')
-    g:MytsrFunc2_args = []
-    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
-    assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args)
-    bw!
-  END
-  call CheckScriptSuccess(lines)
-
   " Using Vim9 lambda expression in legacy context should fail
-  set thesaurusfunc=(a,\ b)\ =>\ g:MytsrFunc2(a,\ b)
+  set thesaurusfunc=(a,\ b)\ =>\ g:MytsrFunc1(21,\ a,\ b)
   new | only
-  let g:MytsrFunc2_args = []
+  let g:MytsrFunc1_args = []
   call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
-  call assert_equal([], g:MytsrFunc2_args)
+  call assert_equal([], g:MytsrFunc1_args)
   bw!
 
   " Use a buffer-local value and a global value
-  func MytsrFunc4(findstart, base)
-    call add(g:MytsrFunc4_args, [a:findstart, a:base])
-    return a:findstart ? 0 : ['sunday']
-  endfunc
   set thesaurusfunc&
-  setlocal thesaurusfunc=function('MytsrFunc4')
+  setlocal thesaurusfunc=function('MytsrFunc1',[22])
   call setline(1, 'sun')
-  let g:MytsrFunc4_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
-  call assert_equal('sunday', getline(1))
-  call assert_equal([[1, ''], [0, 'sun']], g:MytsrFunc4_args)
+  call assert_equal('sun', getline(1))
+  call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args)
   new
   call setline(1, 'sun')
-  let g:MytsrFunc4_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
   call assert_equal('sun', getline(1))
-  call assert_equal([], g:MytsrFunc4_args)
-  set thesaurusfunc=function('MytsrFunc1')
+  call assert_equal([], g:MytsrFunc1_args)
+  set thesaurusfunc=function('MytsrFunc1',[23])
   wincmd w
   call setline(1, 'sun')
-  let g:MytsrFunc4_args = []
+  let g:MytsrFunc1_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
-  call assert_equal('sunday', getline(1))
-  call assert_equal([[1, ''], [0, 'sun']], g:MytsrFunc4_args)
+  call assert_equal('sun', getline(1))
+  call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args)
   %bw!
 
   " set 'thesaurusfunc' to a non-existing function
+  func MytsrFunc2(findstart, base)
+    call add(g:MytsrFunc2_args, [a:findstart, a:base])
+    return a:findstart ? 0 : ['sunday']
+  endfunc
   set thesaurusfunc=MytsrFunc2
   call setline(1, 'ten')
   call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:')
@@ -1550,13 +1468,69 @@ func Test_thesaurusfunc_callback()
   let g:MytsrFunc2_args = []
   call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
   call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args)
+  bw!
+
+  " Vim9 tests
+  let lines =<< trim END
+    vim9script
+
+    # Test for using function()
+    def Vim9tsrFunc(val: number, findstart: number, base: string): any
+      add(g:Vim9tsrFunc_Args, [val, findstart, base])
+      return findstart ? 0 : []
+    enddef
+    set thesaurusfunc=function('Vim9tsrFunc',\ [60])
+    new | only
+    setline(1, 'one')
+    g:Vim9tsrFunc_Args = []
+    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+    assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args)
+    bw!
+
+    # Test for using a lambda
+    &thesaurusfunc = (a, b) => Vim9tsrFunc(61, a, b)
+    new | only
+    setline(1, 'two')
+    g:Vim9tsrFunc_Args = []
+    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+    assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9tsrFunc_Args)
+    bw!
+
+    # Test for using a string(lambda)
+    &thesaurusfunc = '(a, b) => Vim9tsrFunc(62, a, b)'
+    new | only
+    setline(1, 'two')
+    g:Vim9tsrFunc_Args = []
+    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+    assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9tsrFunc_Args)
+    bw!
+
+    # Test for using a variable with a lambda expression
+    var Fn: func = (a, b) => Vim9tsrFunc(63, a, b)
+    &thesaurusfunc = Fn
+    new | only
+    setline(1, 'three')
+    g:Vim9tsrFunc_Args = []
+    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+    assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9tsrFunc_Args)
+    bw!
+
+    # Test for using a string(variable with a lambda expression)
+    Fn = (a, b) => Vim9tsrFunc(64, a, b)
+    &thesaurusfunc = string(Fn)
+    new | only
+    setline(1, 'three')
+    g:Vim9tsrFunc_Args = []
+    feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+    assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9tsrFunc_Args)
+    bw!
+  END
+  call CheckScriptSuccess(lines)
 
   " cleanup
   set thesaurusfunc&
   delfunc MytsrFunc1
   delfunc MytsrFunc2
-  delfunc MytsrFunc3
-  delfunc MytsrFunc4
   %bw!
 endfunc
 
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -3,6 +3,7 @@
 source shared.vim
 source check.vim
 source view_util.vim
+source vim9.vim
 
 func Setup_NewWindow()
   10new
@@ -386,70 +387,6 @@ func Test_normal09a_operatorfunc()
   norm V10j,,
   call assert_equal(22, g:a)
 
-  " Use a lambda function for 'opfunc'
-  unmap <buffer> ,,
-  call cursor(1, 1)
-  let g:a=0
-  nmap <buffer><silent> ,, :set opfunc={type\ ->\ CountSpaces(type)}<CR>g@
-  vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
-  50
-  norm V2j,,
-  call assert_equal(6, g:a)
-  norm V,,
-  call assert_equal(2, g:a)
-  norm ,,l
-  call assert_equal(0, g:a)
-  50
-  exe "norm 0\<c-v>10j2l,,"
-  call assert_equal(11, g:a)
-  50
-  norm V10j,,
-  call assert_equal(22, g:a)
-
-  " use a partial function for 'opfunc'
-  let g:OpVal = 0
-  func! Test_opfunc1(x, y, type)
-    let g:OpVal =  a:x + a:y
-  endfunc
-  set opfunc=function('Test_opfunc1',\ [5,\ 7])
-  normal! g@l
-  call assert_equal(12, g:OpVal)
-  " delete the function and try to use g@
-  delfunc Test_opfunc1
-  call test_garbagecollect_now()
-  call assert_fails('normal! g@l', 'E117:')
-  set opfunc=
-
-  " use a funcref for 'opfunc'
-  let g:OpVal = 0
-  func! Test_opfunc2(x, y, type)
-    let g:OpVal =  a:x + a:y
-  endfunc
-  set opfunc=funcref('Test_opfunc2',\ [4,\ 3])
-  normal! g@l
-  call assert_equal(7, g:OpVal)
-  " delete the function and try to use g@
-  delfunc Test_opfunc2
-  call test_garbagecollect_now()
-  call assert_fails('normal! g@l', 'E933:')
-  set opfunc=
-
-  " Try to use a function with two arguments for 'operatorfunc'
-  let g:OpVal = 0
-  func! Test_opfunc3(x, y)
-    let g:OpVal = 4
-  endfunc
-  set opfunc=Test_opfunc3
-  call assert_fails('normal! g@l', 'E119:')
-  call assert_equal(0, g:OpVal)
-  set opfunc=
-  delfunc Test_opfunc3
-  unlet g:OpVal
-
-  " Try to use a lambda function with two arguments for 'operatorfunc'
-  set opfunc={x,\ y\ ->\ 'done'}
-  call assert_fails('normal! g@l', 'E119:')
-
   " clean up
   unmap <buffer> ,,
   set opfunc=
@@ -504,6 +441,182 @@ func Test_normal09c_operatorfunc()
   set operatorfunc=
 endfunc
 
+" Test for different ways of setting the 'operatorfunc' option
+func Test_opfunc_callback()
+  new
+  func MyopFunc(val, type)
+    let g:OpFuncArgs = [a:val, a:type]
+  endfunc
+
+  " Test for using a function()
+  set opfunc=function('MyopFunc',\ [11])
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([11, 'char'], g:OpFuncArgs)
+
+  " Using a funcref variable to set 'operatorfunc'
+  let Fn = function('MyopFunc', [12])
+  let &opfunc = Fn
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([12, 'char'], g:OpFuncArgs)
+
+  " Using a string(funcref_variable) to set 'operatorfunc'
+  let Fn = function('MyopFunc', [13])
+  let &operatorfunc = string(Fn)
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([13, 'char'], g:OpFuncArgs)
+
+  " Test for using a funcref()
+  set operatorfunc=funcref('MyopFunc',\ [14])
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([14, 'char'], g:OpFuncArgs)
+
+  " Using a funcref variable to set 'operatorfunc'
+  let Fn = funcref('MyopFunc', [15])
+  let &opfunc = Fn
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([15, 'char'], g:OpFuncArgs)
+
+  " Using a string(funcref_variable) to set 'operatorfunc'
+  let Fn = funcref('MyopFunc', [16])
+  let &opfunc = string(Fn)
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([16, 'char'], g:OpFuncArgs)
+
+  " Test for using a lambda function using set
+  set opfunc={a\ ->\ MyopFunc(17,\ a)}
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([17, 'char'], g:OpFuncArgs)
+
+  " Test for using a lambda function using let
+  let &opfunc = {a -> MyopFunc(18, a)}
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([18, 'char'], g:OpFuncArgs)
+
+  " Set 'operatorfunc' to a string(lambda expression)
+  let &opfunc = '{a -> MyopFunc(19, a)}'
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([19, 'char'], g:OpFuncArgs)
+
+  " Set 'operatorfunc' to a variable with a lambda expression
+  let Lambda = {a -> MyopFunc(20, a)}
+  let &opfunc = Lambda
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([20, 'char'], g:OpFuncArgs)
+
+  " Set 'operatorfunc' to a string(variable with a lambda expression)
+  let Lambda = {a -> MyopFunc(21, a)}
+  let &opfunc = string(Lambda)
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([21, 'char'], g:OpFuncArgs)
+
+  " Try to use 'operatorfunc' after the function is deleted
+  func TmpOpFunc(type)
+    let g:OpFuncArgs = [22, a:type]
+  endfunc
+  let &opfunc = function('TmpOpFunc')
+  delfunc TmpOpFunc
+  call test_garbagecollect_now()
+  let g:OpFuncArgs = []
+  call assert_fails('normal! g@l', 'E117:')
+  call assert_equal([], g:OpFuncArgs)
+
+  " Try to use a function with two arguments for 'operatorfunc'
+  func! MyopFunc2(x, y)
+    let g:OpFuncArgs = [a:x, a:y]
+  endfunc
+  set opfunc=MyopFunc2
+  let g:OpFuncArgs = []
+  call assert_fails('normal! g@l', 'E119:')
+  call assert_equal([], g:OpFuncArgs)
+
+  " Try to use a lambda function with two arguments for 'operatorfunc'
+  let &opfunc = {a, b -> MyopFunc(23, b)}
+  let g:OpFuncArgs = []
+  call assert_fails('normal! g@l', 'E119:')
+  call assert_equal([], g:OpFuncArgs)
+
+  " Test for clearing the 'operatorfunc' option
+  set opfunc=''
+  set opfunc&
+
+  call assert_fails("set opfunc=function('abc')", "E700:")
+  call assert_fails("set opfunc=funcref('abc')", "E700:")
+
+  " Using Vim9 lambda expression in legacy context should fail
+  set opfunc=(a)\ =>\ MyopFunc(24,\ a)
+  let g:OpFuncArgs = []
+  call assert_fails('normal! g@l', 'E117:')
+  call assert_equal([], g:OpFuncArgs)
+
+  " set 'operatorfunc' to a non-existing function
+  let &opfunc = function('MyopFunc', [25])
+  call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:')
+  call assert_fails("let &opfunc = function('NonExistingFunc')", 'E700:')
+  let g:OpFuncArgs = []
+  normal! g@l
+  call assert_equal([25, 'char'], g:OpFuncArgs)
+
+  " Vim9 tests
+  let lines =<< trim END
+    vim9script
+
+    # Test for using function()
+    def g:Vim9opFunc(val: number, type: string): void
+      g:OpFuncArgs = [val, type]
+    enddef
+    set opfunc=function('g:Vim9opFunc',\ [60])
+    g:OpFuncArgs = []
+    normal! g@l
+    assert_equal([60, 'char'], g:OpFuncArgs)
+
+    # Test for using a lambda
+    &opfunc = (a) => Vim9opFunc(61, a)
+    g:OpFuncArgs = []
+    normal! g@l
+    assert_equal([61, 'char'], g:OpFuncArgs)
+
+    # Test for using a string(lambda)
+    &opfunc = '(a) => Vim9opFunc(62, a)'
+    g:OpFuncArgs = []
+    normal! g@l
+    assert_equal([62, 'char'], g:OpFuncArgs)
+
+    # Test for using a variable with a lambda expression
+    var Fn: func = (a) => Vim9opFunc(63, a)
+    &opfunc = Fn
+    g:OpFuncArgs = []
+    normal! g@l
+    assert_equal([63, 'char'], g:OpFuncArgs)
+
+    # Test for using a string(variable with a lambda expression)
+    Fn = (a) => Vim9opFunc(64, a)
+    &opfunc = string(Fn)
+    g:OpFuncArgs = []
+    normal! g@l
+    assert_equal([64, 'char'], g:OpFuncArgs)
+    bw!
+  END
+  call CheckScriptSuccess(lines)
+
+  " cleanup
+  set opfunc&
+  delfunc MyopFunc
+  delfunc MyopFunc2
+  unlet g:OpFuncArgs
+  %bw!
+endfunc
+
 func Test_normal10_expand()
   " Test for expand()
   10new
--- a/src/testdir/test_tagfunc.vim
+++ b/src/testdir/test_tagfunc.vim
@@ -127,59 +127,60 @@ endfunc
 
 " Test for different ways of setting the 'tagfunc' option
 func Test_tagfunc_callback()
-  " Test for using a function()
-  func MytagFunc1(pat, flags, info)
-    let g:MytagFunc1_args = [a:pat, a:flags, a:info]
+  func MytagFunc1(val, pat, flags, info)
+    let g:MytagFunc1_args = [a:val, a:pat, a:flags, a:info]
     return v:null
   endfunc
-  set tagfunc=function('MytagFunc1')
+
+  " Test for using a function()
+  set tagfunc=function('MytagFunc1',[10])
   new | only
   let g:MytagFunc1_args = []
   call assert_fails('tag a11', 'E433:')
-  call assert_equal(['a11', '', {}], g:MytagFunc1_args)
+  call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args)
 
   " Using a funcref variable to set 'tagfunc'
-  let Fn = function('MytagFunc1')
+  let Fn = function('MytagFunc1', [11])
   let &tagfunc = Fn
   new | only
   let g:MytagFunc1_args = []
   call assert_fails('tag a12', 'E433:')
-  call assert_equal(['a12', '', {}], g:MytagFunc1_args)
+  call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args)
 
   " Using a string(funcref_variable) to set 'tagfunc'
-  let Fn = function('MytagFunc1')
+  let Fn = function('MytagFunc1', [12])
   let &tagfunc = string(Fn)
   new | only
   let g:MytagFunc1_args = []
   call assert_fails('tag a12', 'E433:')
-  call assert_equal(['a12', '', {}], g:MytagFunc1_args)
+  call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args)
 
   " Test for using a funcref()
   func MytagFunc2(pat, flags, info)
     let g:MytagFunc2_args = [a:pat, a:flags, a:info]
     return v:null
   endfunc
-  set tagfunc=funcref('MytagFunc2')
+  set tagfunc=funcref('MytagFunc1',[13])
   new | only
-  let g:MytagFunc2_args = []
+  let g:MytagFunc1_args = []
   call assert_fails('tag a13', 'E433:')
-  call assert_equal(['a13', '', {}], g:MytagFunc2_args)
+  call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args)
 
   " Using a funcref variable to set 'tagfunc'
-  let Fn = funcref('MytagFunc2')
+  let Fn = funcref('MytagFunc1', [14])
   let &tagfunc = Fn
   new | only
-  let g:MytagFunc2_args = []
+  let g:MytagFunc1_args = []
   call assert_fails('tag a14', 'E433:')
-  call assert_equal(['a14', '', {}], g:MytagFunc2_args)
+  call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args)
 
   " Using a string(funcref_variable) to set 'tagfunc'
-  let Fn = funcref('MytagFunc2')
+  let Fn = funcref('MytagFunc1', [15])
   let &tagfunc = string(Fn)
   new | only
-  let g:MytagFunc2_args = []
+  let g:MytagFunc1_args = []
   call assert_fails('tag a14', 'E433:')
-  call assert_equal(['a14', '', {}], g:MytagFunc2_args)
+  call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args)
 
   " Test for using a script local function
   set tagfunc=<SID>ScriptLocalTagFunc
@@ -205,45 +206,41 @@ func Test_tagfunc_callback()
   call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
 
   " Test for using a lambda function
-  func MytagFunc3(pat, flags, info)
-    let g:MytagFunc3_args = [a:pat, a:flags, a:info]
-    return v:null
-  endfunc
-  set tagfunc={a,\ b,\ c\ ->\ MytagFunc3(a,\ b,\ c)}
+  set tagfunc={a,\ b,\ c\ ->\ MytagFunc1(16,\ a,\ b,\ c)}
   new | only
-  let g:MytagFunc3_args = []
+  let g:MytagFunc1_args = []
   call assert_fails('tag a17', 'E433:')
-  call assert_equal(['a17', '', {}], g:MytagFunc3_args)
+  call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args)
 
   " Set 'tagfunc' to a lambda expression
-  let &tagfunc = {a, b, c -> MytagFunc3(a, b, c)}
+  let &tagfunc = {a, b, c -> MytagFunc1(17, a, b, c)}
   new | only
-  let g:MytagFunc3_args = []
+  let g:MytagFunc1_args = []
   call assert_fails('tag a18', 'E433:')
-  call assert_equal(['a18', '', {}], g:MytagFunc3_args)
+  call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args)
 
   " Set 'tagfunc' to a string(lambda expression)
-  let &tagfunc = '{a, b, c -> MytagFunc3(a, b, c)}'
+  let &tagfunc = '{a, b, c -> MytagFunc1(18, a, b, c)}'
   new | only
-  let g:MytagFunc3_args = []
+  let g:MytagFunc1_args = []
   call assert_fails('tag a18', 'E433:')
-  call assert_equal(['a18', '', {}], g:MytagFunc3_args)
+  call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args)
 
   " Set 'tagfunc' to a variable with a lambda expression
-  let Lambda = {a, b, c -> MytagFunc3(a, b, c)}
+  let Lambda = {a, b, c -> MytagFunc1(19, a, b, c)}
   let &tagfunc = Lambda
   new | only
-  let g:MytagFunc3_args = []
+  let g:MytagFunc1_args = []
   call assert_fails("tag a19", "E433:")
-  call assert_equal(['a19', '', {}], g:MytagFunc3_args)
+  call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args)
 
   " Set 'tagfunc' to a string(variable with a lambda expression)
-  let Lambda = {a, b, c -> MytagFunc3(a, b, c)}
+  let Lambda = {a, b, c -> MytagFunc1(20, a, b, c)}
   let &tagfunc = string(Lambda)
   new | only
-  let g:MytagFunc3_args = []
+  let g:MytagFunc1_args = []
   call assert_fails("tag a19", "E433:")
-  call assert_equal(['a19', '', {}], g:MytagFunc3_args)
+  call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args)
 
   " Test for using a lambda function with incorrect return value
   let Lambda = {s -> strlen(s)}
@@ -260,72 +257,69 @@ func Test_tagfunc_callback()
   let &tagfunc = "{a -> 'abc'}"
   call assert_fails("echo taglist('a')", "E987:")
 
+  " Using Vim9 lambda expression in legacy context should fail
+  set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c)
+  new | only
+  let g:MytagFunc1_args = []
+  call assert_fails("tag a17", "E117:")
+  call assert_equal([], g:MytagFunc1_args)
+
+  " set 'tagfunc' to a non-existing function
+  call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:')
+  call assert_fails("let &tagfunc = function('NonExistingFunc')", 'E700:')
+  call assert_fails("tag axb123", 'E426:')
+  bw!
+
   " Vim9 tests
   let lines =<< trim END
     vim9script
 
     # Test for using function()
-    def MytagFunc1(pat: string, flags: string, info: dict<any>): any
-      g:MytagFunc1_args = [pat, flags, info]
+    def Vim9tagFunc(val: number, pat: string, flags: string, info: dict<any>): any
+      g:Vim9tagFuncArgs = [val, pat, flags, info]
       return null
     enddef
-    set tagfunc=function('MytagFunc1')
+    set tagfunc=function('Vim9tagFunc',\ [60])
+    new | only
+    g:Vim9tagFuncArgs = []
+    assert_fails('tag a10', 'E433:')
+    assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs)
+
+    # Test for using a lambda
+    &tagfunc = (a, b, c) => MytagFunc1(61, a, b, c)
     new | only
     g:MytagFunc1_args = []
-    assert_fails('tag a10', 'E433:')
-    assert_equal(['a10', '', {}], g:MytagFunc1_args)
-
-    # Test for using a lambda
-    def MytagFunc2(pat: string, flags: string, info: dict<any>): any
-      g:MytagFunc2_args = [pat, flags, info]
-      return null
-    enddef
-    &tagfunc = (a, b, c) => MytagFunc2(a, b, c)
-    new | only
-    g:MytagFunc2_args = []
     assert_fails('tag a20', 'E433:')
-    assert_equal(['a20', '', {}], g:MytagFunc2_args)
+    assert_equal([61, 'a20', '', {}], g:MytagFunc1_args)
 
     # Test for using a string(lambda)
-    &tagfunc = '(a, b, c) => MytagFunc2(a, b, c)'
+    &tagfunc = '(a, b, c) => MytagFunc1(62, a, b, c)'
     new | only
-    g:MytagFunc2_args = []
+    g:MytagFunc1_args = []
     assert_fails('tag a20', 'E433:')
-    assert_equal(['a20', '', {}], g:MytagFunc2_args)
+    assert_equal([62, 'a20', '', {}], g:MytagFunc1_args)
 
     # Test for using a variable with a lambda expression
-    var Fn: func = (a, b, c) => MytagFunc2(a, b, c)
+    var Fn: func = (a, b, c) => MytagFunc1(63, a, b, c)
     &tagfunc = Fn
     new | only
-    g:MytagFunc2_args = []
+    g:MytagFunc1_args = []
     assert_fails('tag a30', 'E433:')
-    assert_equal(['a30', '', {}], g:MytagFunc2_args)
+    assert_equal([63, 'a30', '', {}], g:MytagFunc1_args)
 
     # Test for using a variable with a lambda expression
+    Fn = (a, b, c) => MytagFunc1(64, a, b, c)
     &tagfunc = string(Fn)
     new | only
-    g:MytagFunc2_args = []
+    g:MytagFunc1_args = []
     assert_fails('tag a30', 'E433:')
-    assert_equal(['a30', '', {}], g:MytagFunc2_args)
+    assert_equal([64, 'a30', '', {}], g:MytagFunc1_args)
   END
   call CheckScriptSuccess(lines)
 
-  " Using Vim9 lambda expression in legacy context should fail
-  set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc2(a,\ b,\ c)
-  new | only
-  let g:MytagFunc3_args = []
-  call assert_fails("tag a17", "E117:")
-  call assert_equal([], g:MytagFunc3_args)
-
-  " set 'tagfunc' to a non-existing function
-  call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:')
-  call assert_fails("let &tagfunc = function('NonExistingFunc')", 'E700:')
-  call assert_fails("tag axb123", 'E426:')
-
   " cleanup
   delfunc MytagFunc1
   delfunc MytagFunc2
-  delfunc MytagFunc3
   set tagfunc&
   %bw!
 endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3758,
+/**/
     3757,
 /**/
     3756,