Skip to content

Commit

Permalink
patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ign…
Browse files Browse the repository at this point in the history
…ored

Problem:  Vim9: Trailing commands after class/enum keywords ignored
Solution: Remove EX_TRLBAR keyword from command definition
          (Yegappan Lakshmanan)

closes: #14649

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
yegappan authored and chrisbra committed Apr 27, 2024
1 parent 340643e commit ac77318
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
8 changes: 7 additions & 1 deletion runtime/doc/cmdline.txt
@@ -1,4 +1,4 @@
*cmdline.txt* For Vim version 9.1. Last change: 2023 Dec 09
*cmdline.txt* For Vim version 9.1. Last change: 2024 Apr 27


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -650,6 +650,12 @@ followed by another Vim command:
:[range]!
a user defined command without the "-bar" argument |:command|

and the following |Vim9-script| keywords:
:abstract
:class
:enum
:interface

Note that this is confusing (inherited from Vi): With ":g" the '|' is included
in the command, with ":s" it is not.

Expand Down
8 changes: 4 additions & 4 deletions src/ex_cmds.h
Expand Up @@ -129,7 +129,7 @@ EXCMD(CMD_aboveleft, "aboveleft", ex_wrongmodifier,
EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM,
ADDR_NONE),
EXCMD(CMD_abstract, "abstract", ex_class,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
EX_EXTRA|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
ADDR_NONE),
EXCMD(CMD_all, "all", ex_all,
EX_BANG|EX_RANGE|EX_COUNT|EX_TRLBAR,
Expand Down Expand Up @@ -357,7 +357,7 @@ EXCMD(CMD_clast, "clast", ex_cc,
EX_RANGE|EX_COUNT|EX_TRLBAR|EX_BANG,
ADDR_UNSIGNED),
EXCMD(CMD_class, "class", ex_class,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
EX_EXTRA|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
ADDR_NONE),
EXCMD(CMD_close, "close", ex_close,
EX_BANG|EX_RANGE|EX_COUNT|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
Expand Down Expand Up @@ -597,7 +597,7 @@ EXCMD(CMD_enew, "enew", ex_edit,
EX_BANG|EX_TRLBAR,
ADDR_NONE),
EXCMD(CMD_enum, "enum", ex_class,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
EX_EXTRA|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
ADDR_NONE),
EXCMD(CMD_eval, "eval", ex_eval,
EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
Expand Down Expand Up @@ -759,7 +759,7 @@ EXCMD(CMD_intro, "intro", ex_intro,
EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
EXCMD(CMD_interface, "interface", ex_class,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
EX_EXTRA|EX_CMDWIN|EX_LOCK_OK|EX_EXPORT,
ADDR_NONE),
EXCMD(CMD_isearch, "isearch", ex_findpat,
EX_BANG|EX_RANGE|EX_DFLALL|EX_WHOLEFOLD|EX_EXTRA|EX_CMDWIN|EX_LOCK_OK,
Expand Down
52 changes: 52 additions & 0 deletions src/testdir/test_vim9_class.vim
Expand Up @@ -67,6 +67,42 @@ def Test_class_basic()
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | echo 'done'", 3)

# Additional command after "class name"
lines =<< trim END
vim9script
class Something | var x = 10
endclass
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = 10", 2)

# Additional command after "object variable"
lines =<< trim END
vim9script
class Something
var l: list<number> = [] | var y = 10
endclass
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)

# Additional command after "class variable"
lines =<< trim END
vim9script
class Something
static var d = {a: 10} | var y = 10
endclass
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)

# Additional command after "object method"
lines =<< trim END
vim9script
class Something
def Foo() | var y = 10
enddef
endclass
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)

# Try to define a class with the same name as an existing variable
lines =<< trim END
vim9script
Expand Down Expand Up @@ -2237,6 +2273,14 @@ def Test_interface_basics()
END
v9.CheckSourceFailure(lines, 'E1345: Not a valid command in an interface: return 5', 6)

# Additional commands after "interface name"
lines =<< trim END
vim9script
interface Something | var x = 10 | var y = 20
endinterface
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = 10", 2)

lines =<< trim END
vim9script
export interface EnterExit
Expand Down Expand Up @@ -3233,6 +3277,14 @@ def Test_abstract_class()
END
v9.CheckSourceFailure(lines, 'E1316: Class can only be defined in Vim9 script', 1)

# Additional commands after "abstract class"
lines =<< trim END
vim9script
abstract class Something | var x = []
endclass
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = []", 2)

# Abstract class cannot have a "new" function
lines =<< trim END
vim9script
Expand Down
11 changes: 10 additions & 1 deletion src/testdir/test_vim9_enum.vim
Expand Up @@ -97,7 +97,16 @@ def Test_enum_parse()
vim9script
enum Something | endenum
END
v9.CheckSourceFailure(lines, 'E1420: Missing :endenum', 3)
v9.CheckSourceFailure(lines, 'E488: Trailing characters: | endenum', 2)

# another command follows the enum name
lines =<< trim END
vim9script
enum Something | var x = 10
Foo
endenum
END
v9.CheckSourceFailure(lines, 'E488: Trailing characters: | var x = 10', 2)

# Try to define an enum with the same name as an existing variable
lines =<< trim END
Expand Down
8 changes: 8 additions & 0 deletions src/testdir/test_vim9_typealias.vim
Expand Up @@ -172,6 +172,14 @@ def Test_typealias()
END
v9.CheckSourceSuccess(lines)

# another command follows a type alias
lines =<< trim END
vim9script
type MyType = number | var x = 20
assert_equal(20, x)
END
v9.CheckSourceSuccess(lines)

# Sourcing a script twice (which will free script local variables)
# Uses "lines" from the previous test
new
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
376,
/**/
375,
/**/
Expand Down
7 changes: 7 additions & 0 deletions src/vim9class.c
Expand Up @@ -136,6 +136,13 @@ parse_member(
fill_evalarg_from_eap(&evalarg, eap, FALSE);
(void)skip_expr_concatenate(&init_arg, &expr_start, &expr_end, &evalarg);

init_arg = skipwhite(init_arg);
if (*init_arg != NUL)
{
semsg(_(e_trailing_characters_str), init_arg);
return FAIL;
}

// No type specified for the member. Set it to "any" and the correct
// type will be set when the object is instantiated.
if (type == NULL)
Expand Down

0 comments on commit ac77318

Please sign in to comment.