Patch 9.0.1198
Problem:    Abstract class not supported yet.
Solution:   Implement abstract class and add tests.
Files:      src/vim9class.c, src/errors.h, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1197/src/vim9class.c     2023-01-13 19:18:35.029796008 +0000
--- src/vim9class.c     2023-01-14 12:53:08.880443598 +0000
***************
*** 204,220 ****
  {
      int is_class = eap->cmdidx == CMD_class;  // FALSE for :interface
  
-     if (!current_script_is_vim9()
-               || (cmdmod.cmod_flags & CMOD_LEGACY)
-               || !getline_equal(eap->getline, eap->cookie, getsourceline))
-     {
-       if (is_class)
-           emsg(_(e_class_can_only_be_defined_in_vim9_script));
-       else
-           emsg(_(e_interface_can_only_be_defined_in_vim9_script));
-       return;
-     }
- 
      char_u *arg = eap->arg;
      int is_abstract = eap->cmdidx == CMD_abstract;
      if (is_abstract)
--- 204,209 ----
***************
*** 225,230 ****
--- 214,231 ----
            return;
        }
        arg = skipwhite(arg + 5);
+       is_class = TRUE;
+     }
+ 
+     if (!current_script_is_vim9()
+               || (cmdmod.cmod_flags & CMOD_LEGACY)
+               || !getline_equal(eap->getline, eap->cookie, getsourceline))
+     {
+       if (is_class)
+           emsg(_(e_class_can_only_be_defined_in_vim9_script));
+       else
+           emsg(_(e_interface_can_only_be_defined_in_vim9_script));
+       return;
      }
  
      if (!ASCII_ISUPPER(*arg))
***************
*** 493,498 ****
--- 494,505 ----
            {
                char_u *name = uf->uf_name;
                int is_new = STRNCMP(name, "new", 3) == 0;
+               if (is_new && is_abstract)
+               {
+                   emsg(_(e_cannot_define_new_function_in_abstract_class));
+                   success = FALSE;
+                   break;
+               }
                garray_T *fgap = has_static || is_new
                                               ? &classfunctions : &objmethods;
                // Check the name isn't used already.
***************
*** 826,832 ****
                have_new = TRUE;
                break;
            }
!       if (is_class && !have_new)
        {
            // No new() method was defined, add the default constructor.
            garray_T fga;
--- 833,839 ----
                have_new = TRUE;
                break;
            }
!       if (is_class && !is_abstract && !have_new)
        {
            // No new() method was defined, add the default constructor.
            garray_T fga;
*** ../vim-9.0.1197/src/errors.h        2023-01-11 17:59:35.114319167 +0000
--- src/errors.h        2023-01-14 12:52:22.148552589 +0000
***************
*** 3440,3443 ****
--- 3440,3445 ----
        INIT(= N_("E1357: Using \"super\" not in a class function"));
  EXTERN char e_using_super_not_in_child_class[]
        INIT(= N_("E1358: Using \"super\" not in a child class"));
+ EXTERN char e_cannot_define_new_function_in_abstract_class[]
+       INIT(= N_("E1359: Cannot define a \"new\" function in an abstract 
class"));
  #endif
*** ../vim-9.0.1197/src/testdir/test_vim9_class.vim     2023-01-13 
17:36:44.311699799 +0000
--- src/testdir/test_vim9_class.vim     2023-01-14 13:09:13.026734456 +0000
***************
*** 1014,1018 ****
--- 1014,1053 ----
    v9.CheckScriptSuccess(lines)
  enddef
  
+ def Test_abstract_class()
+   var lines =<< trim END
+       vim9script
+       abstract class Base
+         this.name: string
+       endclass
+       class Person extends Base
+         this.age: number
+       endclass
+       var p: Base = Person.new('Peter', 42)
+       assert_equal('Peter', p.name)
+       assert_equal(42, p.age)
+   END
+   v9.CheckScriptSuccess(lines)
+ 
+   lines =<< trim END
+       vim9script
+       abstract class Base
+         this.name: string
+       endclass
+       class Person extends Base
+         this.age: number
+       endclass
+       var p = Base.new('Peter')
+   END
+   v9.CheckScriptFailure(lines, 'E1325: Method not found on class "Base": 
new(')
+ 
+   lines =<< trim END
+       abstract class Base
+         this.name: string
+       endclass
+   END
+   v9.CheckScriptFailure(lines, 'E1316:')
+ enddef
+ 
  
  " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-9.0.1197/src/version.c       2023-01-14 12:40:59.214945169 +0000
--- src/version.c       2023-01-14 12:49:47.264947499 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1198,
  /**/

-- 
"How is your new girlfriend?"
"90-60-90 man!"
"What, pale purple?"

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230114131232.49A561C0916%40moolenaar.net.

Raspunde prin e-mail lui