The help entry for has_key() says that the key must be a string. In
legacy Vim script, however, this works fine:
let dd = {42: '42', v:true: 'T', 3.14: '3.14'}
echo dd->has_key(42)
echo dd->has_key(v:true)
echo dd->has_key(3.14)
In Vim 9 script, the behavior is different:
vim9script
const dd = {42: '42', true: 'T', [3.14]: '3.14'}
echo dd->has_key(42) # OK
echo dd->has_key(v:true) # Error, must be string(v:true)
echo dd->has_key(3.14) # Error, must be string(3.14)
This seems a bit inconsistent to me. I don't have a problem with Vim
9 script being different from legacy script, but I think that either all
the three cases should raise an error, or none of them.
Besides, the documentation does not make it clear that implicit type
casting may happen.
Life.
--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/tdi4ul%24ik8%241%40ciao.gmane.io.
Wednesday, August 17, 2022
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment