patch 9.0.1723: Fix regression in {func} argument of reduce()
Problem: Fix regression in {func} argument of reduce()
Solution: pass function name as string again
Before patch 9.0.0548, passing a string as {func} argument of reduce()
is treated as a function name, but after patch 9.0.0548 it is treated as
an expression instead, which is useless as reduce() doesn't set any v:
variables. This PR restores the behavior of {func} before that patch.
Also correct an emsg() call, as e_string_list_or_blob_required doesn't
contain format specifiers.
closes: #12824
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index ac1f29b..3ff2097 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -1037,6 +1037,10 @@
call assert_equal('Å,s,t,r,ö,m', reduce('Åström', LSTART acc, val LMIDDLE acc .. ',' .. val LEND))
call assert_equal('Å,s,t,r,ö,m', reduce('Åström', LSTART acc, val LMIDDLE acc .. ',' .. val LEND))
call assert_equal(',a,b,c', reduce('abc', LSTART acc, val LMIDDLE acc .. ',' .. val LEND, test_null_string()))
+
+ call assert_equal(0x7d, reduce([0x30, 0x25, 0x08, 0x61], 'or'))
+ call assert_equal(0x7d, reduce(0z30250861, 'or'))
+ call assert_equal('β', reduce('ββββ', 'matchstr'))
END
call v9.CheckLegacyAndVim9Success(lines)
@@ -1052,7 +1056,7 @@
call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E1098:')
call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E1098:')
- call assert_fails("call reduce([1, 2], 'Xdoes_not_exist')", 'E121:')
+ call assert_fails("call reduce([1, 2], 'Xdoes_not_exist')", 'E117:')
call assert_fails("echo reduce(0z01, { acc, val -> 2 * acc + val }, '')", 'E1210:')
call assert_fails("vim9 reduce(0, (acc, val) => (acc .. val), '')", 'E1252:')