mirror of
https://github.com/vim/vim
synced 2025-07-15 16:51:57 +00:00
patch 9.1.1541: Vim9: error when last enum value ends with a comma
Problem: Vim9: error when last enum value ends with a comma Solution: Allow trailing commas in enum values (Yegappan Lakshmanan). closes: #17744 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
1341176e7b
commit
ada6b27ff1
@ -838,6 +838,25 @@ def Test_enum_values()
|
|||||||
END
|
END
|
||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
enum Car
|
||||||
|
Honda,
|
||||||
|
Ford,
|
||||||
|
endenum
|
||||||
|
assert_equal([Car.Honda, Car.Ford], Car.values)
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
enum Car
|
||||||
|
Honda, Ford,
|
||||||
|
endenum
|
||||||
|
assert_equal([Car.Honda, Car.Ford], Car.values)
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
# empty enum
|
# empty enum
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@ -863,7 +882,7 @@ def Test_enum_values()
|
|||||||
Red,
|
Red,
|
||||||
Blue
|
Blue
|
||||||
static def GetValues(): list<A>
|
static def GetValues(): list<A>
|
||||||
return values
|
return values
|
||||||
enddef
|
enddef
|
||||||
endenum
|
endenum
|
||||||
assert_equal([A.Red, A.Blue], A.GetValues())
|
assert_equal([A.Red, A.Blue], A.GetValues())
|
||||||
@ -1050,6 +1069,34 @@ def Test_enum_refcount()
|
|||||||
assert_equal(4, test_refcount(Star.Orion))
|
assert_equal(4, test_refcount(Star.Orion))
|
||||||
END
|
END
|
||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
enum Star
|
||||||
|
Gemini,
|
||||||
|
Orion,
|
||||||
|
endenum
|
||||||
|
|
||||||
|
assert_equal(3, test_refcount(Star))
|
||||||
|
assert_equal(2, test_refcount(Star.Gemini))
|
||||||
|
assert_equal(2, test_refcount(Star.Orion))
|
||||||
|
|
||||||
|
var x = [Star.Gemini]
|
||||||
|
assert_equal(3, test_refcount(Star))
|
||||||
|
assert_equal(3, test_refcount(Star.Gemini))
|
||||||
|
|
||||||
|
def Fn()
|
||||||
|
var y = [Star.Gemini, Star.Orion]
|
||||||
|
assert_equal(6, test_refcount(Star))
|
||||||
|
assert_equal(4, test_refcount(Star.Gemini))
|
||||||
|
enddef
|
||||||
|
Fn()
|
||||||
|
# The instruction in the compiled function adds an additional reference
|
||||||
|
# to the enum.
|
||||||
|
assert_equal(6, test_refcount(Star))
|
||||||
|
assert_equal(3, test_refcount(Star.Gemini))
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Test for defining an enum with additional object variables and methods
|
" Test for defining an enum with additional object variables and methods
|
||||||
|
@ -719,6 +719,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 */
|
||||||
|
/**/
|
||||||
|
1541,
|
||||||
/**/
|
/**/
|
||||||
1540,
|
1540,
|
||||||
/**/
|
/**/
|
||||||
|
@ -1855,6 +1855,7 @@ ex_class(exarg_T *eap)
|
|||||||
int is_class = eap->cmdidx == CMD_class;
|
int is_class = eap->cmdidx == CMD_class;
|
||||||
int is_abstract = eap->cmdidx == CMD_abstract;
|
int is_abstract = eap->cmdidx == CMD_abstract;
|
||||||
int is_enum = eap->cmdidx == CMD_enum;
|
int is_enum = eap->cmdidx == CMD_enum;
|
||||||
|
int added_enum_values = FALSE;
|
||||||
int is_interface;
|
int is_interface;
|
||||||
long start_lnum = SOURCING_LNUM;
|
long start_lnum = SOURCING_LNUM;
|
||||||
char_u *arg = eap->arg;
|
char_u *arg = eap->arg;
|
||||||
@ -2174,9 +2175,12 @@ early_ret:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (enum_end)
|
if (enum_end)
|
||||||
|
{
|
||||||
// Add the enum "values" class variable.
|
// Add the enum "values" class variable.
|
||||||
enum_add_values_member(cl, &classmembers, num_enum_values,
|
enum_add_values_member(cl, &classmembers, num_enum_values,
|
||||||
&type_list);
|
&type_list);
|
||||||
|
added_enum_values = TRUE;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2496,9 +2500,10 @@ early_ret:
|
|||||||
|
|
||||||
vim_free(theline);
|
vim_free(theline);
|
||||||
|
|
||||||
if (success && is_enum && num_enum_values == 0)
|
if (success && is_enum && (num_enum_values == 0 || !added_enum_values))
|
||||||
// Empty enum statement. Add an empty "values" class variable
|
// Empty enum statement. Add an empty "values" class variable
|
||||||
success = enum_add_values_member(cl, &classmembers, 0, &type_list);
|
success = enum_add_values_member(cl, &classmembers, num_enum_values,
|
||||||
|
&type_list);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check a few things
|
* Check a few things
|
||||||
|
Reference in New Issue
Block a user