enddef
enddef
-def Test_nested_func()
+def Test_disassemble_nested_func()
var instr = execute('disassemble NestedOuter')
assert_match('NestedOuter\_s*' ..
'def g:Inner()\_s*' ..
def /Info/
enddef
-def Test_nested_def_list()
+def Test_disassemble_nested_def_list()
var instr = execute('disassemble NestedDefList')
assert_match('NestedDefList\_s*' ..
'def\_s*' ..
CheckDefFailure(lines, 'E1117:')
# nested function inside conditional
- # TODO: should it work when "thecount" is inside the "if"?
lines =<< trim END
vim9script
var thecount = 0
assert_equal(2, Test())
END
CheckScriptSuccess(lines)
+
+ # also works when "thecount" is inside the "if" block
+ lines =<< trim END
+ vim9script
+ if true
+ var thecount = 0
+ def Test(): number
+ def TheFunc(): number
+ thecount += 1
+ return thecount
+ enddef
+ return TheFunc()
+ enddef
+ endif
+ defcompile
+ assert_equal(1, Test())
+ assert_equal(2, Test())
+ END
+ CheckScriptSuccess(lines)
enddef
def Test_not_nested_function()
r = eap->skip ? OK : FAIL;
goto theend;
}
+
+ // copy over the block scope IDs before compiling
+ if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0)
+ {
+ int block_depth = cctx->ctx_ufunc->uf_block_depth;
+
+ ufunc->uf_block_ids = ALLOC_MULT(int, block_depth);
+ if (ufunc->uf_block_ids != NULL)
+ {
+ mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids,
+ sizeof(int) * block_depth);
+ ufunc->uf_block_depth = block_depth;
+ }
+ }
+
if (func_needs_compiling(ufunc, PROFILING(ufunc))
&& compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx)
== FAIL)
// Define a local variable for the function reference.
lvar_T *lvar = reserve_local(cctx, name_start, name_end - name_start,
TRUE, ufunc->uf_func_type);
- int block_depth = cctx->ctx_ufunc->uf_block_depth;
if (lvar == NULL)
goto theend;
if (generate_FUNCREF(cctx, ufunc) == FAIL)
goto theend;
r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
-
- // copy over the block scope IDs
- if (block_depth > 0)
- {
- ufunc->uf_block_ids = ALLOC_MULT(int, block_depth);
- if (ufunc->uf_block_ids != NULL)
- {
- mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids,
- sizeof(int) * block_depth);
- ufunc->uf_block_depth = block_depth;
- }
- }
}
// TODO: warning for trailing text?