mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.1.0994: Vim9: not able to use comment after opening curly brace
Problem: Vim9: not able to use comment after opening curly brace (lifepillar) Solution: allow to use comments after curly braces of an inner-block, modify the logic to search for comment in a line, update Vim9 tests to use specific class type instead of any (Yegappan Lakshmanan) fixes: #16363 closes: #16405 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
c97e869535
commit
0072ceedc6
@ -4345,23 +4345,20 @@ def Test_lockvar_object_variable()
|
|||||||
END
|
END
|
||||||
v9.CheckSourceFailure(lines, 'E1335: Variable "val4" in class "C" is not writable')
|
v9.CheckSourceFailure(lines, 'E1335: Variable "val4" in class "C" is not writable')
|
||||||
|
|
||||||
# TODO: the following tests use type "any" for argument. Need a run time
|
|
||||||
# check for access. Probably OK as is for now.
|
|
||||||
|
|
||||||
# read-only lockvar from object method arg
|
# read-only lockvar from object method arg
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
|
||||||
class C
|
class C
|
||||||
var val5: number
|
var val5: number
|
||||||
def Lock(o_any: any)
|
def Lock(c: C)
|
||||||
lockvar o_any.val5
|
lockvar c.val5
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
var o = C.new(3)
|
var o = C.new(3)
|
||||||
o.Lock(C.new(5))
|
o.Lock(C.new(5))
|
||||||
END
|
END
|
||||||
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"')
|
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val5" in class "C"')
|
||||||
|
|
||||||
# read-only lockvar from class method arg
|
# read-only lockvar from class method arg
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
@ -4369,14 +4366,14 @@ def Test_lockvar_object_variable()
|
|||||||
|
|
||||||
class C
|
class C
|
||||||
var val6: number
|
var val6: number
|
||||||
static def Lock(o_any: any)
|
static def Lock(c: C)
|
||||||
lockvar o_any.val6
|
lockvar c.val6
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
var o = C.new(3)
|
var o = C.new(3)
|
||||||
C.Lock(o)
|
C.Lock(o)
|
||||||
END
|
END
|
||||||
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"')
|
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val6" in class "C"')
|
||||||
|
|
||||||
#
|
#
|
||||||
# lockvar of public object variable
|
# lockvar of public object variable
|
||||||
@ -4444,14 +4441,14 @@ def Test_lockvar_object_variable()
|
|||||||
|
|
||||||
class C
|
class C
|
||||||
public var val5: number
|
public var val5: number
|
||||||
def Lock(o_any: any)
|
def Lock(c: C)
|
||||||
lockvar o_any.val5
|
lockvar c.val5
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
var o = C.new(3)
|
var o = C.new(3)
|
||||||
o.Lock(C.new(5))
|
o.Lock(C.new(5))
|
||||||
END
|
END
|
||||||
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"', 1)
|
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val5" in class "C"', 1)
|
||||||
|
|
||||||
# lockvar from class method arg
|
# lockvar from class method arg
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
@ -4459,14 +4456,14 @@ def Test_lockvar_object_variable()
|
|||||||
|
|
||||||
class C
|
class C
|
||||||
public var val6: number
|
public var val6: number
|
||||||
static def Lock(o_any: any)
|
static def Lock(c: C)
|
||||||
lockvar o_any.val6
|
lockvar c.val6
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
var o = C.new(3)
|
var o = C.new(3)
|
||||||
C.Lock(o)
|
C.Lock(o)
|
||||||
END
|
END
|
||||||
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"', 1)
|
v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val6" in class "C"', 1)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Test trying to lock a class variable from various places
|
" Test trying to lock a class variable from various places
|
||||||
|
@ -4697,6 +4697,23 @@ def Test_test_override_defcompile()
|
|||||||
test_override('defcompile', 0)
|
test_override('defcompile', 0)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
" Test for using a comment after the opening curly brace of an inner block.
|
||||||
|
def Test_comment_after_inner_block()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
def F(G: func)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
F(() => { # comment1
|
||||||
|
F(() => { # comment2
|
||||||
|
echo 'ok' # comment3
|
||||||
|
}) # comment4
|
||||||
|
}) # comment5
|
||||||
|
END
|
||||||
|
v9.CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
" The following messes up syntax highlight, keep near the end.
|
" The following messes up syntax highlight, keep near the end.
|
||||||
if has('python3')
|
if has('python3')
|
||||||
def Test_python3_command()
|
def Test_python3_command()
|
||||||
|
@ -595,6 +595,27 @@ def Test_autocommand_block()
|
|||||||
unlet g:otherVar
|
unlet g:otherVar
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_block_in_a_string()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
def Foo(): string
|
||||||
|
var x = ' => { # abc'
|
||||||
|
return x
|
||||||
|
enddef
|
||||||
|
|
||||||
|
assert_equal(' => { # abc', Foo())
|
||||||
|
|
||||||
|
def Bar(): string
|
||||||
|
var x = " => { # abc"
|
||||||
|
return x
|
||||||
|
enddef
|
||||||
|
|
||||||
|
assert_equal(" => { # abc", Bar())
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
func g:NoSuchFunc()
|
func g:NoSuchFunc()
|
||||||
echo 'none'
|
echo 'none'
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -859,6 +859,92 @@ function_using_block_scopes(ufunc_T *fp, cstack_T *cstack)
|
|||||||
cstack->cs_flags[i] |= CSF_FUNC_DEF;
|
cstack->cs_flags[i] |= CSF_FUNC_DEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip over all the characters in a single quoted string starting at "p" and
|
||||||
|
* return a pointer to the character following the ending single quote.
|
||||||
|
* If the ending single quote is missing, then return a pointer to the NUL
|
||||||
|
* character.
|
||||||
|
*/
|
||||||
|
static char_u *
|
||||||
|
skip_single_quote_string(char_u *p)
|
||||||
|
{
|
||||||
|
p++; // skip the beginning single quote
|
||||||
|
while (*p != NUL)
|
||||||
|
{
|
||||||
|
// Within the string, a single quote can be escaped by using
|
||||||
|
// two single quotes.
|
||||||
|
if (*p == '\'' && *(p + 1) == '\'')
|
||||||
|
p += 2;
|
||||||
|
else if (*p == '\'')
|
||||||
|
{
|
||||||
|
p++; // skip the ending single quote
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MB_PTR_ADV(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip over all the characters in a double quoted string starting at "p" and
|
||||||
|
* return a pointer to the character following the ending double quote.
|
||||||
|
* If the ending double quote is missing, then return a pointer to the NUL
|
||||||
|
* character.
|
||||||
|
*/
|
||||||
|
static char_u *
|
||||||
|
skip_double_quote_string(char_u *p)
|
||||||
|
{
|
||||||
|
p++; // skip the beginning double quote
|
||||||
|
while (*p != NUL)
|
||||||
|
{
|
||||||
|
// Within the string, a double quote can be escaped by
|
||||||
|
// preceding it with a backslash.
|
||||||
|
if (*p == '\\' && *(p + 1) == '"')
|
||||||
|
p += 2;
|
||||||
|
else if (*p == '"')
|
||||||
|
{
|
||||||
|
p++; // skip the ending double quote
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MB_PTR_ADV(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the start of a Vim9 comment (#) in the line starting at "line".
|
||||||
|
* If a comment is not found, then returns a pointer to the end of the
|
||||||
|
* string (NUL).
|
||||||
|
*/
|
||||||
|
static char_u *
|
||||||
|
find_start_of_vim9_comment(char_u *line)
|
||||||
|
{
|
||||||
|
char_u *p = line;
|
||||||
|
|
||||||
|
while (*p != NUL)
|
||||||
|
{
|
||||||
|
if (*p == '\'')
|
||||||
|
// Skip a single quoted string.
|
||||||
|
p = skip_single_quote_string(p);
|
||||||
|
else if (*p == '"')
|
||||||
|
// Skip a double quoted string.
|
||||||
|
p = skip_double_quote_string(p);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (*p == '#')
|
||||||
|
// Found the start of a Vim9 comment
|
||||||
|
break;
|
||||||
|
MB_PTR_ADV(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the body of a function, put every line in "newlines".
|
* Read the body of a function, put every line in "newlines".
|
||||||
* This stops at "}", "endfunction" or "enddef".
|
* This stops at "}", "endfunction" or "enddef".
|
||||||
@ -1123,7 +1209,17 @@ get_function_body(
|
|||||||
if (nesting_def[nesting] ? *p != '#' : *p != '"')
|
if (nesting_def[nesting] ? *p != '#' : *p != '"')
|
||||||
{
|
{
|
||||||
// Not a comment line: check for nested inline function.
|
// Not a comment line: check for nested inline function.
|
||||||
|
|
||||||
|
if (nesting_inline[nesting])
|
||||||
|
{
|
||||||
|
// A comment (#) can follow the opening curly brace of a
|
||||||
|
// block statement. Need to ignore the comment and look
|
||||||
|
// for the opening curly brace before the comment.
|
||||||
|
end = find_start_of_vim9_comment(p) - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
end = p + STRLEN(p) - 1;
|
end = p + STRLEN(p) - 1;
|
||||||
|
|
||||||
while (end > p && VIM_ISWHITE(*end))
|
while (end > p && VIM_ISWHITE(*end))
|
||||||
--end;
|
--end;
|
||||||
if (end > p + 1 && *end == '{' && VIM_ISWHITE(end[-1]))
|
if (end > p + 1 && *end == '{' && VIM_ISWHITE(end[-1]))
|
||||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
994,
|
||||||
/**/
|
/**/
|
||||||
993,
|
993,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user