Skip to content

Commit d79ea47

Browse files
yegappanchrisbra
authored andcommitted
patch 9.1.1040: Vim9: imported type cannot be used as func return type
Problem: Vim9: imported type cannot be used as func return type (Dayvid Albuquerque) Solution: temporarily reset the is_export flag (Yegappan Lakshmanan) fixes: #16489 closes: #16492 Signed-off-by: Yegappan Lakshmanan <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 4335fcf commit d79ea47

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/testdir/test_vim9_import.vim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3387,4 +3387,37 @@ def Test_import_locked_var()
33873387
v9.CheckScriptFailure(lines, 'E741: Value is locked: Foo', 3)
33883388
enddef
33893389

3390+
" Test for using an autoload imported class as the function return type
3391+
def Test_imported_class_as_def_func_rettype()
3392+
var lines =<< trim END
3393+
vim9script
3394+
3395+
export class Foo
3396+
var name: string = "foo"
3397+
endclass
3398+
END
3399+
writefile(lines, 'Ximportclassrettype1.vim', 'D')
3400+
3401+
lines =<< trim END
3402+
vim9script
3403+
3404+
import autoload "./Ximportclassrettype1.vim" as A
3405+
3406+
export def CreateFoo(): A.Foo
3407+
return A.Foo.new()
3408+
enddef
3409+
END
3410+
writefile(lines, 'Ximportclassrettype2.vim', 'D')
3411+
3412+
lines =<< trim END
3413+
vim9script
3414+
3415+
import './Ximportclassrettype2.vim' as B
3416+
3417+
var foo = B.CreateFoo()
3418+
assert_equal('foo', foo.name)
3419+
END
3420+
v9.CheckScriptSuccess(lines)
3421+
enddef
3422+
33903423
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/userfunc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5472,11 +5472,19 @@ define_function(
54725472
// The function may use script variables from the context.
54735473
function_using_block_scopes(fp, cstack);
54745474

5475+
// The argument types and the return type may use an imported type.
5476+
// In that case, the imported file will be sourced. To avoid treating
5477+
// everything in the imported file as exported, temporarily reset
5478+
// is_export.
5479+
int save_is_export = is_export;
5480+
is_export = FALSE;
5481+
54755482
if (parse_argument_types(fp, &argtypes, varargs, &arg_objm,
54765483
obj_members, obj_member_count) == FAIL)
54775484
{
54785485
SOURCING_LNUM = lnum_save;
54795486
free_fp = fp_allocated;
5487+
is_export = save_is_export;
54805488
goto erret;
54815489
}
54825490
varargs = FALSE;
@@ -5486,8 +5494,10 @@ define_function(
54865494
{
54875495
SOURCING_LNUM = lnum_save;
54885496
free_fp = fp_allocated;
5497+
is_export = save_is_export;
54895498
goto erret;
54905499
}
5500+
is_export = save_is_export;
54915501
SOURCING_LNUM = lnum_save;
54925502
}
54935503
else

src/version.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred)
1414
* It has been changed beyond recognition since then.
1515
*
16-
* Differences between version 8.2 and 9.0 can be found with ":help version9".
16+
* Differences between version 8.2 and 9.1 can be found with ":help version9".
1717
* Differences between version 7.4 and 8.x can be found with ":help version8".
1818
* Differences between version 6.4 and 7.x can be found with ":help version7".
1919
* Differences between version 5.8 and 6.x can be found with ":help version6".
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1040,
707709
/**/
708710
1039,
709711
/**/

0 commit comments

Comments
 (0)