summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-01-30 20:24:23 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-30 20:24:23 +0000
commitb8bebd0cd78679162228ee08265c9a5b3a409e1c (patch)
treeb458889dcc2a1d54922340db18a303863dd66b89
parenteb45ad25ab5022e5bead0dbb19fe5704924f918a (diff)
downloadvim-git-b8bebd0cd78679162228ee08265c9a5b3a409e1c.tar.gz
patch 9.0.1265: using an interface method may give a compilation errorv9.0.1265
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)
-rw-r--r--src/testdir/test_vim9_class.vim17
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c12
3 files changed, 30 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 023068c7d..a8128c7c7 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index 5436c99fc..24a27707a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1265,
+/**/
1264,
/**/
1263,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 3f97c007b..27b71f78f 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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)
{