]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1355: no error when declaring a class twice v9.0.1355
authorBram Moolenaar <Bram@vim.org>
Sat, 25 Feb 2023 19:59:31 +0000 (19:59 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 25 Feb 2023 19:59:31 +0000 (19:59 +0000)
Problem:    No error when declaring a class twice. (Ernie Rael)
Solution:   Pass different flags when declaring the class. (closes #12057)

src/testdir/test_vim9_class.vim
src/version.c
src/vim9class.c

index c268dde50eea7a1d5be3ea8397e92672c5afb57f..87c1d4a08c0a5f8d4f1c7addebc1d9ee54701387 100644 (file)
@@ -164,6 +164,28 @@ def Test_class_basic()
   v9.CheckScriptSuccess(lines)
 enddef
 
+def Test_class_defined_twice()
+  # class defined twice should fail
+  var lines =<< trim END
+      vim9script
+      class There
+      endclass
+      class There
+      endclass
+  END
+  v9.CheckScriptFailure(lines, 'E1041: Redefining script item: "There"')
+
+  # one class, reload same script twice is OK
+  lines =<< trim END
+      vim9script
+      class There
+      endclass
+  END
+  writefile(lines, 'XclassTwice.vim', 'D')
+  source XclassTwice.vim
+  source XclassTwice.vim
+enddef
+
 def Test_class_interface_wrong_end()
   var lines =<< trim END
       vim9script
@@ -1012,14 +1034,13 @@ def Test_class_implements_interface()
         this.member: string
       endinterface
 
-      class SomeImpl implements Some, Another
+      class AnotherImpl implements Some, Another
         this.member = 'abc'
         static count: number
         def Method(nr: number)
           echo nr
         enddef
       endclass
-
   END
   v9.CheckScriptSuccess(lines)
 
index 315f91eac2b0d2824bd83a1240250e0e7b888743..785f76e09945c2fc8c56803e0d9c608396f9fc63 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1355,
 /**/
     1354,
 /**/
index 4431640d4cbeb74176dcd3272fcb8f5792d98284..a2b186ec5a36e6fa7b3e7e67e0b1356074c672c3 100644 (file)
@@ -230,7 +230,8 @@ object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl)
     void
 ex_class(exarg_T *eap)
 {
-    int is_class = eap->cmdidx == CMD_class;  // FALSE for :interface
+    int            is_class = eap->cmdidx == CMD_class;  // FALSE for :interface
+    long    start_lnum = SOURCING_LNUM;
 
     char_u *arg = eap->arg;
     int is_abstract = eap->cmdidx == CMD_abstract;
@@ -1097,8 +1098,9 @@ early_ret:
        tv.v_type = VAR_CLASS;
        tv.vval.v_class = cl;
        is_export = class_export;
+       SOURCING_LNUM = start_lnum;
        set_var_const(cl->class_name, current_sctx.sc_sid,
-                                            NULL, &tv, FALSE, ASSIGN_DECL, 0);
+                                                      NULL, &tv, FALSE, 0, 0);
        return;
     }