patch 9.1.1541: Vim9: error when last enum value ends with a comma

Commit: 
https://github.com/vim/vim/commit/ada6b27ff1b17584779a3b6d55f89f5db1aec75e
Author: Yegappan Lakshmanan <yegap...@yahoo.com>
Date:   Mon Jul 14 21:27:34 2025 +0200

    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 <yegap...@yahoo.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/testdir/test_vim9_enum.vim b/src/testdir/test_vim9_enum.vim
index d2ccb77cf..49976e6d8 100644
--- a/src/testdir/test_vim9_enum.vim
+++ b/src/testdir/test_vim9_enum.vim
@@ -838,6 +838,25 @@ def Test_enum_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)
+
+  lines =<< trim END
+    vim9script
+    enum Car
+      Honda, Ford,
+    endenum
+    assert_equal([Car.Honda, Car.Ford], Car.values)
+  END
+  v9.CheckSourceSuccess(lines)
+
   # empty enum
   lines =<< trim END
     vim9script
@@ -863,7 +882,7 @@ def Test_enum_values()
       Red,
       Blue
       static def GetValues(): list<A>
-       return values
+        return values
       enddef
     endenum
     assert_equal([A.Red, A.Blue], A.GetValues())
@@ -1050,6 +1069,34 @@ def Test_enum_refcount()
     assert_equal(4, test_refcount(Star.Orion))
   END
   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
 
 " Test for defining an enum with additional object variables and methods
diff --git a/src/version.c b/src/version.c
index a8c368fed..37c2c9146 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 */
+/**/
+    1541,
 /**/
     1540,
 /**/
diff --git a/src/vim9class.c b/src/vim9class.c
index a82cc1332..ea225c11d 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -1855,6 +1855,7 @@ ex_class(exarg_T *eap)
     int                is_class = eap->cmdidx == CMD_class;
     int                is_abstract = eap->cmdidx == CMD_abstract;
     int                is_enum = eap->cmdidx == CMD_enum;
+    int                added_enum_values = FALSE;
     int                is_interface;
     long       start_lnum = SOURCING_LNUM;
     char_u     *arg = eap->arg;
@@ -2174,9 +2175,12 @@ early_ret:
                break;
 
            if (enum_end)
+           {
                // Add the enum "values" class variable.
                enum_add_values_member(cl, &classmembers, num_enum_values,
                                                        &type_list);
+               added_enum_values = TRUE;
+           }
            continue;
        }
 
@@ -2496,9 +2500,10 @@ early_ret:
 
     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
-       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

-- 
-- 
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/E1ubP6o-005iHR-Mh%40256bit.org.

Raspunde prin e-mail lui