patch 9.1.0925: Vim9: expression compiled when not necessary
Commit:
https://github.com/vim/vim/commit/e203841e0dbae2851e23f87f5bd89a458895d0d6
Author: Yegappan Lakshmanan <[email protected]>
Date: Sat Dec 14 19:59:24 2024 +0100
patch 9.1.0925: Vim9: expression compiled when not necessary
Problem: Vim9: expression compiled when not necessary
Solution: do not compile when ctx_skip is set, add a few more
Vim9 expressions tests (Yegappan Lakshmanan)
closes: #16218
Signed-off-by: Yegappan Lakshmanan <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index bb08943ff..1848c016c 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -3090,6 +3090,14 @@ def Test_heredoc_expr()
END
LINES
v9.CheckDefAndScriptFailure(lines, 'E15: Invalid expression: "}"')
+
+ # dangling "}"
+ lines =<< trim LINES
+ var text =<< trim eval END
+ aa}a
+ END
+ LINES
+ v9.CheckDefAndScriptFailure(lines, "E1278: Stray '}' without a matching '{':
aa}a")
enddef
" Test for assigning to a multi-dimensional list item.
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index bcb590d10..82f808862 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2038,6 +2038,12 @@ def Test_if_const_expr()
.. 'ccc'
)->setline(1)
endif
+
+ if 1
+ # do nothing
+ else
+ var [a] = [10]
+ endif
enddef
def Test_if_const_expr_fails()
@@ -2234,6 +2240,15 @@ def Test_echowindow_cmd()
# output goes in message window
popup_clear()
+
+ # Invalid range
+ var lines =<< trim END
+ def Foo()
+ :$echowindow "foo"
+ enddef
+ defcompile
+ END
+ v9.CheckDefAndScriptFailure(lines, 'E16: Invalid range')
enddef
def Test_for_outside_of_function()
@@ -5133,6 +5148,29 @@ def Test_unknown_type_in_typecast()
v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got
bool', 2)
enddef
+" Test for calling a function as a method with a list argument
+" This exercises some conditions in the assignment statement parsing code.
+def Test_method_call_with_list_arg()
+ var lines =<< trim END
+ vim9script
+
+ def Foo(l: list<number>)
+ g:save_list = l
+ enddef
+
+ def Bar()
+ var a = 10
+ var b = 20
+ [a, b]->Foo()
+ enddef
+
+ g:save_list = []
+ Bar()
+ assert_equal([10, 20], g:save_list)
+ END
+ v9.CheckSourceSuccess(lines)
+enddef
+
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new
diff --git a/src/version.c b/src/version.c
index ac695905d..789df38a2 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 */
+/**/
+ 925,
/**/
924,
/**/
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 64e219599..776e6d6b8 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3342,7 +3342,7 @@ compile_assignment(
// For "[var, var] = expr" drop the "expr" value.
// Also for "[var, var; _] = expr".
- if (cac.cac_var_count > 0 &&
+ if (cctx->ctx_skip != SKIP_YES && cac.cac_var_count > 0 &&
(!cac.cac_semicolon || !cac.cac_did_generate_slice))
{
if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
--
--
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/E1tMXbX-00DsnC-Ji%40256bit.org.