Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Vim's bug of :return in try-catch #565

Closed
wants to merge 1 commit into from

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Dec 22, 2017

Vim script の :return {expr}{expr} で例外が飛んでも :catch で補足されないようです.回避する修正を入れました.

Copy link
Member

@ujihisa ujihisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🍣

@rhysd rhysd force-pushed the avoid-vim-bug-return-in-try-catch branch 2 times, most recently from f9572be to 565910d Compare December 22, 2017 02:08
@rhysd
Copy link
Contributor Author

rhysd commented Dec 22, 2017

一応もう1人ぐらいレビューしていただいたらマージします

@thinca
Copy link
Member

thinca commented Dec 22, 2017

ありがとうございます!正確には問題になるのは例外ではなく Vim のエラーです。
例えば以下のコードは問題ありません。

function! s:throw(msg) abort
  throw a:msg
endfunction

function! s:test() abort
  try
    return s:throw('foo')
  catch
    return 'ok'
  endtry
endfunction

echo s:test()
" => ok

呼び出した先でのエラーも大丈夫(内部構造理解してないですが、たぶん例外に変換されている?)。

function! s:throw() abort
  let _ = [] == 0
endfunction

function! s:test() abort
  try
    return s:throw()
  catch
    return 'ok'
  endtry
endfunction

echo s:test()
" => ok

@thinca
Copy link
Member

thinca commented Dec 22, 2017

という点を踏まえた上でも対策はしておいた方が安全かな…?

@rhysd
Copy link
Contributor Author

rhysd commented Dec 22, 2017

すみません,どういうエラーが飛んでくるかまでは考慮せず問題が起こりそうな箇所はすべて回避するコードを入れている状態です.確認したほうが良いでしょうか

@rhysd
Copy link
Contributor Author

rhysd commented Dec 22, 2017

ざっと全部見てみましたが,全箇所回避コードを入れなくて大丈夫そうですね.閉じます.@thinca さん,@ujihisa さん,レビューありがとうございます!

@rhysd rhysd closed this Dec 22, 2017
@rhysd rhysd deleted the avoid-vim-bug-return-in-try-catch branch December 22, 2017 02:58
@tyru
Copy link
Member

tyru commented Dec 22, 2017

ret は Funcref だった場合も考えて Ret にすべきだと思います。

@tyru
Copy link
Member

tyru commented Dec 22, 2017

あと既存のグローバル関数名と被った時エラーにならないように l: 付けないとダメだった…
あとでやります。

@tyru
Copy link
Member

tyru commented Dec 22, 2017

あっ…すみません。コメント読んでませんでした…orz
確かに @thinca さんが言った再現条件だと回避コード入れなくてよさそうです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants