annotate runtime/ftplugin/vb.vim @ 33090:461541d860ac v9.0.1830

patch 9.0.1830: Vim9: crash when accessing a null object Commit: https://github.com/vim/vim/commit/d7085a06358c22250a27186bb7d52112ed4addd1 Author: Gianmaria Bajo <mg1979.git@gmail.com> Date: Thu Aug 31 18:15:26 2023 +0200 patch 9.0.1830: Vim9: crash when accessing a null object Problem: Vim9: crash when accessing a null object Solution: Check accessing a NULL object in def function An object is NULL when the variable is declared, but the constructor isn't called. Accessing/setting a member on the object crashed Vim. Note: this happens inside def functions, at script level things work differently. Accessing a NULL object member results in E1360 (correctly), while setting a value on it results in E1012 (type mismatch) so there's still something to fix. closes: #12973 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Gianmaria Bajo <mg1979.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Thu, 31 Aug 2023 18:30:03 +0200
parents 786b2a8ec970
children 8ae680be2a51
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim filetype plugin file
26219
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
2 " Language: Visual Basic (ft=vb)
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
3 " Maintainer: Doug Kearns <dougkearns@gmail.com>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
4 " Previous Maintainer: Johannes Zellner <johannes@zellner.org>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
5 " Last Change: 2021 Nov 17
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
26219
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
7 if exists("b:did_ftplugin")
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
8 finish
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
9 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 let b:did_ftplugin = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
26219
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
12 let s:cpo_save = &cpo
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
13 set cpo&vim
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
14
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
15 setlocal comments=sr:'\ -,mb:'\ \ ,el:'\ \ ,:'
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
16 setlocal commentstring='\ %s
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
17 setlocal formatoptions-=t formatoptions+=croql
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
18
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
19 let b:undo_ftplugin = "setlocal com< cms< fo<"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " we need this wrapper, as call doesn't allow a count
26219
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
22 function! s:VbSearch(pattern, flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 let cnt = v:count1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 while cnt > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 call search(a:pattern, a:flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let cnt = cnt - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 endwhile
26219
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
28 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
26219
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
30 if !exists("no_plugin_maps") && !exists("no_vb_maps")
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
31 nnoremap <buffer> <silent> [[ <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sbW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
32 vnoremap <buffer> <silent> [[ <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sbW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
33 nnoremap <buffer> <silent> ]] <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
34 vnoremap <buffer> <silent> ]] <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
35 nnoremap <buffer> <silent> [] <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sbW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
36 vnoremap <buffer> <silent> [] <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sbW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
37 nnoremap <buffer> <silent> ][ <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
38 vnoremap <buffer> <silent> ][ <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sW')<CR>
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
39 let b:undo_ftplugin .= " | sil! exe 'nunmap <buffer> [[' | sil! exe 'vunmap <buffer> [['" .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
40 \ " | sil! exe 'nunmap <buffer> ]]' | sil! exe 'vunmap <buffer> ]]'" .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
41 \ " | sil! exe 'nunmap <buffer> []' | sil! exe 'vunmap <buffer> []'" .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
42 \ " | sil! exe 'nunmap <buffer> ][' | sil! exe 'vunmap <buffer> ]['"
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
43 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
26219
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
45 " TODO: line start anchors are almost certainly overly restrictive - allow
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
46 " after statement separators. Even in QuickBasic only block IF statements
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
47 " were required to be at the start of a line.
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
48 if exists("loaded_matchit") && !exists("b:match_words")
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
49 let b:match_ignorecase = 1
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
50 let b:match_words =
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
51 \ '\%(^\s*\)\@<=\<if\>.*\<then\>\s*\%($\|''\):\%(^\s*\)\@<=\<else\>:\%(^\s*\)\@<=\<elseif\>:\%(^\s*\)\@<=\<end\>\s\+\<if\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
52 \ '\%(^\s*\)\@<=\<for\>:\%(^\s*\)\@<=\<next\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
53 \ '\%(^\s*\)\@<=\<while\>:\%(^\s*\)\@<=\<wend\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
54 \ '\%(^\s*\)\@<=\<do\>:\%(^\s*\)\@<=\<loop\>\s\+\<while\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
55 \ '\%(^\s*\)\@<=\<select\>\s\+\<case\>:\%(^\s*\)\@<=\<case\>:\%(^\s*\)\@<=\<end\>\s\+\<select\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
56 \ '\%(^\s*\)\@<=\<enum\>:\%(^\s*\)\@<=\<end\>\s\<enum\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
57 \ '\%(^\s*\)\@<=\<with\>:\%(^\s*\)\@<=\<end\>\s\<with\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
58 \ '\%(^\s*\)\@<=\%(\<\%(private\|public\)\>\s\+\)\=\<function\>\s\+\([^ \t(]\+\):\%(^\s*\)\@<=\<\1\>\s*=:\%(^\s*\)\@<=\<end\>\s\+\<function\>,' .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
59 \ '\%(^\s*\)\@<=\%(\<\%(private\|public\)\>\s\+\)\=\<sub\>\s\+:\%(^\s*\)\@<=\<end\>\s\+\<sub\>'
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
60 let b:undo_ftplugin .= " | unlet! b:match_words b:match_ignorecase"
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
61 endif
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
62
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
63 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
64 let b:browsefilter = "Visual Basic Source Files (*.bas)\t*.bas\n" .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
65 \ "Visual Basic Form Files (*.frm)\t*.frm\n" .
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
66 \ "All Files (*.*)\t*.*\n"
786b2a8ec970 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
67 let b:undo_ftplugin .= " | unlet! b:browsefilter"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 let &cpo = s:cpo_save
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 unlet s:cpo_save