Hi Bram and List!

How to reproduce:
- Start pure vim with new file a.vim
  $ vim -N -u NONE a.vim

(1)
:let str='abcde'
:let nn=3
:echo str[nn:]
E121: Undefined variable: nn:
E15: Invalid expression: str[nn:]


(2)
:let str='abcde'
:let g:nr=3
:echo str[g:nr:]
E121: Undefined variable: g:nr:
E15: Invalid expression: str[g:nr:]


Expected behavior:
- Both displayed 'de'

Actual behavior
- Occured E121 and E15.

I wrote a patch. (including test)
Please check this.
--
Best Regards,
Hirohito Higashi (a.k.a h_east)

-- 
-- 
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].
For more options, visit https://groups.google.com/d/optout.
diff -r 5fe47f21f158 src/eval.c
--- a/src/eval.c	Tue Nov 03 22:15:05 2015 +0100
+++ b/src/eval.c	Wed Nov 04 12:57:16 2015 +0900
@@ -115,6 +115,8 @@
 static char *e_float_as_string = N_("E806: using Float as a String");
 #endif
 
+#define NAMESPACE_CHAR	(char_u *)"abglstvw"
+
 static dictitem_T	globvars_var;		/* variable used for g: */
 #define globvarht globvardict.dv_hashtab
 
@@ -20347,10 +20349,20 @@
 {
     char_u	*p;
     int		len;
+    int		kcnt = 0;
 
     /* Find the end of the name. */
     for (p = *arg; eval_isnamec(*p); ++p)
-	;
+    {
+	if (*p == ':')
+	{
+	    len = (int)(p - *arg);
+
+	    if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL)
+		    || len > 1 || ++kcnt > 1)
+		break;
+	}
+    }
     if (p == *arg)	    /* no name found */
 	return 0;
 
@@ -20450,6 +20462,8 @@
     int		mb_nest = 0;
     int		br_nest = 0;
     char_u	*p;
+    int		len;
+    int		kcnt = 0;
 
     if (expr_start != NULL)
     {
@@ -20485,6 +20499,14 @@
 	    if (*p == NUL)
 		break;
 	}
+	else if (br_nest == 0 && mb_nest == 0 && *p == ':')
+	{
+	    len = (int)(p - arg);
+
+	    if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL)
+		    || len > 1 || ++kcnt > 1)
+		break;
+	}
 
 	if (mb_nest == 0)
 	{
diff -r 5fe47f21f158 src/testdir/test_eval.in
--- a/src/testdir/test_eval.in	Tue Nov 03 22:15:05 2015 +0100
+++ b/src/testdir/test_eval.in	Wed Nov 04 12:57:16 2015 +0900
@@ -218,6 +218,24 @@
 0:call setpos('.', sp)
 jyl:$put
 :"
+:" substring and variable name
+:let str = 'abcdef'
+:let n = 3
+:$put =str[n:]
+:$put =str[:n]
+:$put =str[n:n]
+:unlet n
+:let nn = 3
+:$put =str[nn:]
+:$put =str[:nn]
+:$put =str[nn:nn]
+:unlet nn
+:let b:nn = 4
+:$put =str[b:nn:]
+:$put =str[:b:nn]
+:$put =str[b:nn:b:nn]
+:unlet b:nn
+:"
 :/^start:/+1,$wq! test.out
 :" vim: et ts=4 isk-=\: fmr=???,???
 :call getchar()
diff -r 5fe47f21f158 src/testdir/test_eval.ok
Binary file src/testdir/test_eval.ok has changed

Raspunde prin e-mail lui