Skip to content

Commit b8bebd0

Browse files
committed
patch 9.0.1265: using an interface method may give a compilation error
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)
1 parent eb45ad2 commit b8bebd0

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/testdir/test_vim9_class.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,23 @@ def Test_call_interface_method()
10491049
unlet g:result
10501050
END
10511051
v9.CheckScriptSuccess(lines)
1052+
1053+
# No class that implements the interface.
1054+
lines =<< trim END
1055+
vim9script
1056+
1057+
interface IWithEE
1058+
def Enter(): any
1059+
def Exit(): void
1060+
endinterface
1061+
1062+
def With1(ee: IWithEE, F: func)
1063+
var r = ee.Enter()
1064+
enddef
1065+
1066+
defcompile
1067+
END
1068+
v9.CheckScriptSuccess(lines)
10521069
enddef
10531070

10541071
def Test_class_used_as_type()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1265,
698700
/**/
699701
1264,
700702
/**/

src/vim9compile.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,16 @@ compile_def_function(
31813181
}
31823182
ufunc->uf_args_visible = ufunc->uf_args.ga_len;
31833183

3184+
// Compiling a function in an interface is done to get the function type.
3185+
// No code is actually compiled.
3186+
if (ufunc->uf_class != NULL
3187+
&& (ufunc->uf_class->class_flags & CLASS_INTERFACE))
3188+
{
3189+
ufunc->uf_def_status = UF_NOT_COMPILED;
3190+
ret = OK;
3191+
goto erret;
3192+
}
3193+
31843194
/*
31853195
* Loop over all the lines of the function and generate instructions.
31863196
*/
@@ -3705,7 +3715,7 @@ compile_def_function(
37053715
iemsg("Type stack underflow");
37063716
goto erret;
37073717
}
3708-
}
3718+
} // END of the loop over all the function body lines.
37093719

37103720
if (cctx.ctx_scope != NULL)
37113721
{

0 commit comments

Comments
 (0)