patch 9.1.1586: Vim9: can define an enum/interface in a function Commit: https://github.com/vim/vim/commit/9239eadc71a61d35543c758920a15d582b812390 Author: Yegappan Lakshmanan <yegap...@yahoo.com> Date: Thu Jul 24 19:14:51 2025 +0200
patch 9.1.1586: Vim9: can define an enum/interface in a function Problem: Vim9: can define an enum/interface in a function (lacygoill) Solution: Give an error when defining an enum or an interface inside a function (Yegappan Lakshmanan) fixes: #17835 fixes: #17837 closes: #17837 Signed-off-by: Yegappan Lakshmanan <yegap...@yahoo.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/runtime/doc/tags b/runtime/doc/tags index 69811f999..0045bae80 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -4618,6 +4618,8 @@ E143 autocmd.txt /*E143* E1432 vim9.txt /*E1432* E1433 vim9.txt /*E1433* E1434 vim9.txt /*E1434* +E1435 vim9class.txt /*E1435* +E1436 vim9class.txt /*E1436* E144 various.txt /*E144* E145 starting.txt /*E145* E146 change.txt /*E146* diff --git a/runtime/doc/vim9class.txt b/runtime/doc/vim9class.txt index d2f43aefb..82c7573b3 100644 --- a/runtime/doc/vim9class.txt +++ b/runtime/doc/vim9class.txt @@ -1,4 +1,4 @@ -*vim9class.txt* For Vim version 9.1. Last change: 2025 Apr 21 +*vim9class.txt* For Vim version 9.1. Last change: 2025 Jul 24 VIM REFERENCE MANUAL by Bram Moolenaar @@ -584,6 +584,8 @@ protected object methods, class variables and class methods. An interface can extend another interface using "extends". The sub-interface inherits all the instance variables and methods from the super interface. +An interface cannot be defined inside a function. *E1436* + ============================================================================== 6. More class details *Vim9-class* *Class* *class* @@ -971,7 +973,7 @@ of that class. Unlike typical object instantiation with the |new()| method, enum instances cannot be created this way. An enum can only be defined in a |Vim9| script file. *E1414* -An enum cannot be defined inside a function. +An enum cannot be defined inside a function. *E1435* *E1415* An enum name must start with an uppercase letter. The name of an enum value diff --git a/src/errors.h b/src/errors.h index 16a0fb3ed..8bb521492 100644 --- a/src/errors.h +++ b/src/errors.h @@ -3630,8 +3630,12 @@ EXTERN char e_concrete_method_str_override_with_generic_method_in_class_str[] INIT(= N_("E1433: Overriding concrete method \"%s\" in class \"%s\" with a generic method")); EXTERN char e_generic_method_str_type_arguments_mismatch_in_class_str[] INIT(= N_("E1434: Mismatched number of type variables for generic method \"%s\" in class \"%s\"")); +EXTERN char e_enum_can_only_be_used_in_script[] + INIT(= N_("E1435: Enum can only be used in a script")); +EXTERN char e_interface_can_only_be_used_in_script[] + INIT(= N_("E1436: Interface can only be used in a script")); #endif -// E1435 - E1499 unused (reserved for Vim9 class support) +// E1437 - E1499 unused (reserved for Vim9 class support) EXTERN char e_cannot_mix_positional_and_non_positional_str[] INIT(= N_("E1500: Cannot mix positional and non-positional arguments: %s")); EXTERN char e_fmt_arg_nr_unused_str[] diff --git a/src/po/vim.pot b/src/po/vim.pot index ca9cbdd18..be30ce557 100644 --- a/src/po/vim.pot +++ b/src/po/vim.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION " "Report-Msgid-Bugs-To: " -"POT-Creation-Date: 2025-07-21 21:33+0200 " +"POT-Creation-Date: 2025-07-24 19:13+0200 " "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE " "Last-Translator: FULL NAME <EMAIL@ADDRESS> " "Language-Team: LANGUAGE <l...@li.org> " @@ -8571,6 +8571,12 @@ msgid "" "class \"%s\"" msgstr "" +msgid "E1435: Enum can only be used in a script" +msgstr "" + +msgid "E1436: Interface can only be used in a script" +msgstr "" + #, c-format msgid "E1500: Cannot mix positional and non-positional arguments: %s" msgstr "" diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 33dbc98b2..7e0a5100b 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -13168,4 +13168,18 @@ func Test_class_selfref_gc() call v9.CheckSourceSuccess(lines) endfunc +" Test for defining an interface in a function +def Test_interface_defined_in_function() + var lines =<< trim END + vim9script + def Fn() + var x = 1 + interface Foo + endinterface + enddef + defcompile + END + v9.CheckScriptFailure(lines, 'E1436: Interface can only be used in a script', 2) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/testdir/test_vim9_enum.vim b/src/testdir/test_vim9_enum.vim index 4f0cf640e..be4c8f6d5 100644 --- a/src/testdir/test_vim9_enum.vim +++ b/src/testdir/test_vim9_enum.vim @@ -1664,4 +1664,19 @@ func Test_class_selfref_gc() call v9.CheckSourceSuccess(lines) endfunc +" Test for defining an enum in a function +def Test_enum_defined_in_function() + var lines =<< trim END + vim9script + def Fn() + var x = 1 + enum Foo + Red, + endenum + enddef + defcompile + END + v9.CheckScriptFailure(lines, 'E1435: Enum can only be used in a script', 2) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index c894f2f80..b0382651c 100644 --- a/src/version.c +++ b/src/version.c @@ -719,6 +719,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1586, /**/ 1585, /**/ diff --git a/src/vim9compile.c b/src/vim9compile.c index 8b7064bd7..f9998ceff 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -4750,6 +4750,14 @@ compile_def_function_body( emsg(_(e_class_can_only_be_used_in_script)); return FAIL; + case CMD_enum: + emsg(_(e_enum_can_only_be_used_in_script)); + return FAIL; + + case CMD_interface: + emsg(_(e_interface_can_only_be_used_in_script)); + return FAIL; + case CMD_type: emsg(_(e_type_can_only_be_used_in_script)); return FAIL; -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1uezlc-0081Bu-MM%40256bit.org.