]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0989: Vim9: Whitespace after the final enum value causes a syntax error v9.1.0989
authorDoug Kearns <dougkearns@gmail.com>
Sat, 4 Jan 2025 16:12:24 +0000 (17:12 +0100)
committerChristian Brabandt <cb@256bit.org>
Sat, 4 Jan 2025 16:12:24 +0000 (17:12 +0100)
Problem:  Vim9: Whitespace after the final enum value causes a syntax
          error
Solution: Fix parsing to allow whitespace after the final enum value.
          (Doug Kearns)

closes: #16383

Signed-off-by: Doug Kearns <dougkearns@gmail.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_codestyle.vim
src/testdir/test_vim9_enum.vim
src/version.c
src/vim9class.c

index 83f52ef34cd6032bacf113f1bee3c8785c30b93c..51c1209d4ff32e2f553105d53b09888f3eb629ff 100644 (file)
@@ -85,6 +85,7 @@ def Test_test_files()
             && fname !~ 'test_let.vim'
             && fname !~ 'test_tagjump.vim'
             && fname !~ 'test_vim9_cmd.vim'
+            && fname !~ 'test_vim9_enum.vim'
       cursor(1, 1)
       var lnum = search(
           fname =~ 'test_vim9_assign.vim' ? '[^=]\s$'
index a5fb26fcf393856d523518675611b904804e947c..74eb468805bcfb41b52ca17e3ebb6cb268f9c48f 100644 (file)
@@ -908,6 +908,18 @@ def Test_enum_comments()
   END
   v9.CheckSourceSuccess(lines)
 
+  lines =<< trim END
+    vim9script
+    enum Car   # cars
+      # before enum
+      Honda(), # honda
+      # before enum
+      Ford()   # ford
+    endenum
+    assert_equal(1, Car.Ford.ordinal)
+  END
+  v9.CheckSourceSuccess(lines)
+
   # Test for using an unsupported comment
   lines =<< trim END
     vim9script
@@ -921,6 +933,29 @@ def Test_enum_comments()
   v9.CheckSourceFailure(lines, 'E1170: Cannot use #{ to start a comment', 4)
 enddef
 
+" Test trailing whitespace after enum values
+def Test_enum_whitespace()
+  var lines =<< trim END
+    vim9script
+    enum Car
+      Honda, 
+      Ford   
+    endenum
+    defcompile
+  END
+  v9.CheckSourceSuccess(lines)
+
+  lines =<< trim END
+    vim9script
+    enum Car
+      Honda(), 
+      Ford()   
+    endenum
+    defcompile
+  END
+  v9.CheckSourceSuccess(lines)
+enddef
+
 " Test string() with enums
 def Test_enum_string()
   var lines =<< trim END
index 987aa9b3f23e29fa2a1cf29176388d5121052fc2..99f41030ff0783873b0dc0750fc29758dc3a8a4f 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    989,
 /**/
     988,
 /**/
index 22db751e5a266ed355c55125f952acdfc9f0ca38..7c7700ba19bd413b866a7ba8bc71121c4f672fa7 100644 (file)
@@ -1623,6 +1623,8 @@ enum_parse_values(
        }
     }
 
+    p = skipwhite(p);
+
     if (*p != NUL && *p != '#')
     {
        if (did_emsg == did_emsg_before)