diff src/vim9class.c @ 31732:ef7a9a7eb197 v9.0.1198

patch 9.0.1198: abstract class not supported yet Commit: https://github.com/vim/vim/commit/24a8d06d7f4db0865f374ced2f4d4b57cbc5b9e4 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 14 13:12:06 2023 +0000 patch 9.0.1198: abstract class not supported yet Problem: Abstract class not supported yet. Solution: Implement abstract class and add tests.
author Bram Moolenaar <Bram@vim.org>
date Sat, 14 Jan 2023 14:15:06 +0100
parents 2b523bbb3a6f
children d3d3ed2c09f6
line wrap: on
line diff
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -204,17 +204,6 @@ ex_class(exarg_T *eap)
 {
     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)
@@ -225,6 +214,18 @@ ex_class(exarg_T *eap)
 	    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,6 +494,12 @@ early_ret:
 	    {
 		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,7 +833,7 @@ early_ret:
 		have_new = TRUE;
 		break;
 	    }
-	if (is_class && !have_new)
+	if (is_class && !is_abstract && !have_new)
 	{
 	    // No new() method was defined, add the default constructor.
 	    garray_T fga;