On Sa, 08 Mai 2021, Christian Brabandt wrote:

> Trying to convert vim-airline to vim9 script, I see the following crash:
> 
> I see the following error before Vim crashes and most likely there is a 
> problem with my newly created vim9 script, but I don't think Vim should 
> crash then. I guess the error makes the instruction pointer null.
> 

I think the crash was caused by this function:

,----
| def airline#highlighter#exec(group: string, clrs: list<any>): void
|   [...]
|   if old_hi != new_hi || !s:hl_group_exists(group)
|     var cmd = ''
|     cmd = printf('hi %s%s', group, s:GetHiCmd(colors))
|     try
|       :exe cmd
|     catch /^Vim\%((\a\+)\)\=:E421:/
|       group=matchstr(v:exception, '\w\+\ze=')
|       var color=matchstr(v:exception, '=\zs\w\+')
|       let cmd=substitute(cmd, color, 'grey', 'g')
|       exe cmd
|       airline#util#warning('color definition for group ' .. group .. ' not 
found, using grey as fallback')
|     catch
|       airline#util#warning('Error when running command: '. cmd)
|     endtry
|     [...]
|   endif
| enddef
`----

I think the crucial part is the catch section, trying to parse 
v:exception and trying to reuse the function argument name group.

I have that part now rewritten as this:

,----
|   catch /^Vim\%((\a\+)\)\=:E421:/
|     var grp = matchstr(v:exception, '\w\+\ze=')
|     var clr = matchstr(v:exception, '=\zs\w\+')
|     cmd = substitute(cmd, clr, 'grey', 'g')
|     :exe cmd
`----

and at least it is not crashing anymore.


Best,
Christian
-- 
Wir haben verlernt, die Augen auf etwas ruhen zu lassen. Deshalb
erkennen wir so wenig.
                -- Jean Giono

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20210508114947.GI95831%40256bit.org.

Raspunde prin e-mail lui