]> granicus.if.org Git - vim/commitdiff
patch 9.0.1265: using an interface method may give a compilation error v9.0.1265
authorBram Moolenaar <Bram@vim.org>
Mon, 30 Jan 2023 20:24:23 +0000 (20:24 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 30 Jan 2023 20:24:23 +0000 (20:24 +0000)
Problem:    Using an interface method may give a compilation error.
Solution:   Do not try to compile the body of a method of an interface.
            (closes #11885)

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

index 023068c7d4f34343dce7ce4d3bf30591a0aba052..a8128c7c77fd82a6519bc16e9fdee941a82cfd26 100644 (file)
@@ -1049,6 +1049,23 @@ def Test_call_interface_method()
     unlet g:result
   END
   v9.CheckScriptSuccess(lines)
+
+  # No class that implements the interface.
+  lines =<< trim END
+      vim9script
+
+      interface IWithEE
+          def Enter(): any
+          def Exit(): void
+      endinterface
+
+      def With1(ee: IWithEE, F: func)
+          var r = ee.Enter()
+      enddef
+
+      defcompile
+  END
+  v9.CheckScriptSuccess(lines)
 enddef
 
 def Test_class_used_as_type()
index 5436c99fc9d41ae6eaa48d3a32db8ab2438e1fdb..24a27707aae1543879813d9108cff4464dd833f7 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1265,
 /**/
     1264,
 /**/
index 3f97c007bb17570561eee287c088885cb125e715..27b71f78fd43502d9c2f76d27ad175bb09b3756c 100644 (file)
@@ -3181,6 +3181,16 @@ compile_def_function(
     }
     ufunc->uf_args_visible = ufunc->uf_args.ga_len;
 
+    // Compiling a function in an interface is done to get the function type.
+    // No code is actually compiled.
+    if (ufunc->uf_class != NULL
+                          && (ufunc->uf_class->class_flags & CLASS_INTERFACE))
+    {
+       ufunc->uf_def_status = UF_NOT_COMPILED;
+       ret = OK;
+       goto erret;
+    }
+
     /*
      * Loop over all the lines of the function and generate instructions.
      */
@@ -3705,7 +3715,7 @@ nextline:
            iemsg("Type stack underflow");
            goto erret;
        }
-    }
+    } // END of the loop over all the function body lines.
 
     if (cctx.ctx_scope != NULL)
     {