]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2085: Vim9: abstract can be used in interface v9.0.2085
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 2 Nov 2023 19:57:32 +0000 (20:57 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 2 Nov 2023 19:58:58 +0000 (20:58 +0100)
Problem:  Vim9: abstract can be used in interface
Solution: Disallow the use of abstract in an interface

fixes: #13456
closes: #13464

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/errors.h
src/testdir/test_vim9_class.vim
src/version.c
src/vim9class.c

index 26ecf094043348addc94aaf5ebd1c21a98f0bc29..85439ba925fca158d6b11bda246c10d260ef0b43 100644 (file)
@@ -3560,8 +3560,10 @@ EXTERN char e_using_typealias_as_string[]
        INIT(= N_("E1402: Using type alias \"%s\" as a String"));
 EXTERN char e_using_typealias_as_value[]
        INIT(= N_("E1403: Type alias \"%s\" cannot be used as a value"));
+EXTERN char e_abstract_cannot_be_used_in_interface[]
+       INIT(= N_("E1404: Abstract cannot be used in an interface"));
 #endif
-// E1404 - E1499 unused (reserved for Vim9 class support)
+// E1405 - 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[]
index b3d9841247992423dedfb9ee145361158db9d90b..1f639e2b3f17de7de320076c1f81d96e6982e83f 100644 (file)
@@ -5567,7 +5567,26 @@ def Test_abstract_method()
       enddef
     endclass
   END
-  v9.CheckSourceSuccess(lines)
+  v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
+
+  # Use abstract static method in an interface
+  lines =<< trim END
+    vim9script
+    interface A
+      abstract static def Foo()
+      enddef
+    endinterface
+  END
+  v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
+
+  # Use abstract static variable in an interface
+  lines =<< trim END
+    vim9script
+    interface A
+      abstract static foo: number = 10
+    endinterface
+  END
+  v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
 
   # Abbreviate the "abstract" keyword
   lines =<< trim END
index 7511e5c1890ddf4b4ee965dc4f5ef12e91c26076..e136a671eced67c5b258e910c153e58dcad3c30f 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2085,
 /**/
     2084,
 /**/
index ede310b457ff734e65807bd4bad8d52d4580ff43..08c371389cd8752e88eec668b0fc0d448f0f1ec8 100644 (file)
@@ -1557,26 +1557,27 @@ early_ret:
                break;
            }
 
+           p = skipwhite(pa + 8);
+           if (STRNCMP(p, "def", 3) != 0 && STRNCMP(p, "static", 6) != 0)
+           {
+               emsg(_(e_abstract_must_be_followed_by_def_or_static));
+               break;
+           }
+
            if (!is_class)
-               // ignore "abstract" in an interface (as all the methods in an
-               // interface are abstract.
-               p = skipwhite(pa + 8);
-           else
            {
-               if (!is_abstract)
-               {
-                   semsg(_(e_abstract_method_in_concrete_class), pa);
-                   break;
-               }
+               // "abstract" not supported in an interface
+               emsg(_(e_abstract_cannot_be_used_in_interface));
+               break;
+           }
 
-               abstract_method = TRUE;
-               p = skipwhite(pa + 8);
-               if (STRNCMP(p, "def", 3) != 0)
-               {
-                   emsg(_(e_abstract_must_be_followed_by_def));
-                   break;
-               }
+           if (!is_abstract)
+           {
+               semsg(_(e_abstract_method_in_concrete_class), pa);
+               break;
            }
+
+           abstract_method = TRUE;
        }
 
        int has_static = FALSE;