Skip to content

Commit 6655bef

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0991: v:stacktrace has wrong type in Vim9 script
Problem: v:stacktrace has wrong type in Vim9 script. Solution: Change the type to t_list_dict_any. Fix grammar in docs. (zeertzjq) closes: #16390 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent cf1f555 commit 6655bef

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

runtime/doc/builtin.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*builtin.txt* For Vim version 9.1. Last change: 2025 Jan 05
1+
*builtin.txt* For Vim version 9.1. Last change: 2025 Jan 06
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -5002,12 +5002,12 @@ getstacktrace() *getstacktrace()*
50025002
Returns the current stack trace of Vim scripts.
50035003
Stack trace is a |List|, of which each item is a |Dictionary|
50045004
with the following items:
5005-
funcref The funcref if the stack is at the function,
5006-
otherwise this item is not exist.
5005+
funcref The funcref if the stack is at a function,
5006+
otherwise this item is omitted.
50075007
event The string of the event description if the
5008-
stack is at autocmd event, otherwise this item
5009-
is not exist.
5010-
lnum The line number of the script on the stack.
5008+
stack is at an autocmd event, otherwise this
5009+
item is omitted.
5010+
lnum The line number in the script on the stack.
50115011
filepath The file path of the script on the stack.
50125012

50135013
Return type: list<dict<any>>

src/evalvars.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static struct vimvar
161161
{VV_NAME("t_typealias", VAR_NUMBER), NULL, VV_RO},
162162
{VV_NAME("t_enum", VAR_NUMBER), NULL, VV_RO},
163163
{VV_NAME("t_enumvalue", VAR_NUMBER), NULL, VV_RO},
164-
{VV_NAME("stacktrace", VAR_LIST), &t_list_string, VV_RO},
164+
{VV_NAME("stacktrace", VAR_LIST), &t_list_dict_any, VV_RO},
165165
};
166166

167167
// shorthand

src/testdir/test_stacktrace.vim

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Test for getstacktrace() and v:stacktrace
22

3+
import './vim9.vim' as v9
4+
35
let s:thisfile = expand('%:p')
46
let s:testdir = s:thisfile->fnamemodify(':h')
57

@@ -34,7 +36,7 @@ func Test_getstacktrace()
3436
source Xscript1
3537
call Xfunc1()
3638
call AssertStacktrace([
37-
\ #{funcref: funcref('Test_getstacktrace'), lnum: 35, filepath: s:thisfile},
39+
\ #{funcref: funcref('Test_getstacktrace'), lnum: 37, filepath: s:thisfile},
3840
\ #{funcref: funcref('Xfunc1'), lnum: 5, filepath: Filepath('Xscript1')},
3941
\ #{funcref: funcref('Xfunc2'), lnum: 4, filepath: Filepath('Xscript2')},
4042
\ ], g:stacktrace)
@@ -61,7 +63,7 @@ func Test_getstacktrace_event()
6163
source Xscript1
6264
source Xscript2
6365
call AssertStacktrace([
64-
\ #{funcref: funcref('Test_getstacktrace_event'), lnum: 62, filepath: s:thisfile},
66+
\ #{funcref: funcref('Test_getstacktrace_event'), lnum: 64, filepath: s:thisfile},
6567
\ #{event: 'SourcePre Autocommands for "*"', lnum: 7, filepath: Filepath('Xscript1')},
6668
\ #{funcref: funcref('Xfunc'), lnum: 4, filepath: Filepath('Xscript1')},
6769
\ ], g:stacktrace)
@@ -98,10 +100,33 @@ func Test_vstacktrace()
98100
endtry
99101
call assert_equal([], v:stacktrace)
100102
call AssertStacktrace([
101-
\ #{funcref: funcref('Test_vstacktrace'), lnum: 95, filepath: s:thisfile},
103+
\ #{funcref: funcref('Test_vstacktrace'), lnum: 97, filepath: s:thisfile},
102104
\ #{funcref: funcref('Xfunc1'), lnum: 5, filepath: Filepath('Xscript1')},
103105
\ #{funcref: funcref('Xfunc2'), lnum: 4, filepath: Filepath('Xscript2')},
104106
\ ], stacktrace)
105107
endfunc
106108

109+
func Test_zzz_stacktrace_vim9()
110+
let lines =<< trim [SCRIPT]
111+
var stacktrace = getstacktrace()
112+
assert_notequal([], stacktrace)
113+
for d in stacktrace
114+
assert_true(has_key(d, 'lnum'))
115+
endfor
116+
try
117+
throw 'Exception from s:Func'
118+
catch
119+
assert_notequal([], v:stacktrace)
120+
assert_equal(len(stacktrace), len(v:stacktrace))
121+
for d in v:stacktrace
122+
assert_true(has_key(d, 'lnum'))
123+
endfor
124+
endtry
125+
[SCRIPT]
126+
call v9.CheckDefSuccess(lines)
127+
" FIXME: v:stacktrace is not cleared after the exception handling, and this
128+
" test has to be run as the last one because of this.
129+
" call assert_equal([], v:stacktrace)
130+
endfunc
131+
107132
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

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

0 commit comments

Comments
 (0)