comparison runtime/doc/vim9.txt @ 23827:7e0d8f1cae7d v8.2.2455

patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent Commit: https://github.com/vim/vim/commit/2e5910bfbb05957c10c9c69756dfa342557e9a8b Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 3 17:41:24 2021 +0100 patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent Problem: Vim9: key type that can be used for literal dict and indexing is inconsistent. Solution: Allow using number and bool as key for a literal dict. (#7771)
author Bram Moolenaar <Bram@vim.org>
date Wed, 03 Feb 2021 17:45:06 +0100
parents 34b4eb3a8458
children 5b37a0bf7e3a
comparison
equal deleted inserted replaced
23826:71d7c2500ee3 23827:7e0d8f1cae7d
545 var dict = {'': value} # empty key 545 var dict = {'': value} # empty key
546 546
547 In case the key needs to be an expression, square brackets can be used, just 547 In case the key needs to be an expression, square brackets can be used, just
548 like in JavaScript: > 548 like in JavaScript: >
549 var dict = {["key" .. nr]: value} 549 var dict = {["key" .. nr]: value}
550
551 The key type can be string, number, bool or float. Other types result in an
552 error. A number can be given with and without the []: >
553 var dict = {123: 'without', [456]: 'with'}
554 echo dict
555 {'456': 'with', '123': 'without'}
550 556
551 557
552 No :xit, :t, :append, :change or :insert ~ 558 No :xit, :t, :append, :change or :insert ~
553 559
554 These commands are too easily confused with local variable names. 560 These commands are too easily confused with local variable names.