Skip to content
Permalink
Browse files

patch 8.1.1692: using *{} for literal dict is not backwards compatible

Problem:    Using *{} for literal dict is not backwards compatible. (Yasuhiro
            Matsumoto)
Solution:   Use ~{} instead.
  • Loading branch information...
brammool committed Jul 14, 2019
1 parent 37d9f17 commit b8be54dcc517c9d57b62409945b7d4b90b6c3071
@@ -60,7 +60,7 @@ Dictionary An associative, unordered array: Each entry has a key and a
value. |Dictionary|
Examples:
{'blue': "#0000ff", 'red': "#ff0000"}
*{blue: "#0000ff", red: "#ff0000"}
~{blue: "#0000ff", red: "#ff0000"}

Funcref A reference to a function |Funcref|.
Example: function("strlen")
@@ -482,10 +482,10 @@ entry. Note that the String '04' and the Number 04 are different, since the
Number will be converted to the String '4'. The empty string can also be used
as a key.
*literal-Dict*
To avoid having to put quotes around every key the *{} form can be used. This
To avoid having to put quotes around every key the ~{} form can be used. This
does require the key to consist only of ASCII letters, digits, '-' and '_'.
Example: >
let mydict = *{zero: 0, one_key: 1, two-key: 2, 333: 3}
let mydict = ~{zero: 0, one_key: 1, two-key: 2, 333: 3}
Note that 333 here is the string "333". Empty keys are not possible here.

A value can be any expression. Using a Dictionary for a value creates a
@@ -178,7 +178,7 @@ DETAILS *popup-function-details*
popup_atcursor({what}, {options}) *popup_atcursor()*
Show the {what} above the cursor, and close it when the cursor
moves. This works like: >
call popup_create({what}, *{
call popup_create({what}, ~{
\ pos: 'botleft',
\ line: 'cursor-1',
\ col: 'cursor',
@@ -191,7 +191,7 @@ popup_beval({what}, {options}) *popup_beval()*
Show the {what} above the position from 'ballooneval' and
close it when the mouse moves. This works like: >
let pos = screenpos(v:beval_winnr, v:beval_lnum, v:beval_col)
call popup_create({what}, *{
call popup_create({what}, ~{
\ pos: 'botleft',
\ line: pos.row - 1,
\ col: pos.col,
@@ -240,7 +240,7 @@ popup_create({what}, {options}) *popup_create()*

popup_dialog({what}, {options}) *popup_dialog()*
Just like |popup_create()| but with these default options: >
call popup_create({what}, *{
call popup_create({what}, ~{
\ pos: 'center',
\ zindex: 200,
\ drag: 1,
@@ -249,7 +249,7 @@ popup_dialog({what}, {options}) *popup_dialog()*
\})
< Use {options} to change the properties. E.g. add a 'filter'
option with value 'popup_filter_yesno'. Example: >
call popup_create('do you want to quit (Yes/no)?', *{
call popup_create('do you want to quit (Yes/no)?', ~{
\ filter: 'popup_filter_yesno',
\ callback: 'QuitCallback',
\ })
@@ -356,7 +356,7 @@ popup_menu({what}, {options}) *popup_menu()*
items with cursorkeys, and close it an item is selected with
Space or Enter. {what} should have multiple lines to make this
useful. This works like: >
call popup_create({what}, *{
call popup_create({what}, ~{
\ pos: 'center',
\ zindex: 200,
\ drag: 1,
@@ -391,7 +391,7 @@ popup_move({id}, {options}) *popup_move()*
popup_notification({what}, {options}) *popup_notification()*
Show the {what} for 3 seconds at the top of the Vim window.
This works like: >
call popup_create({what}, *{
call popup_create({what}, ~{
\ line: 1,
\ col: 10,
\ minwidth: 20,
@@ -732,15 +732,15 @@ Prompt the user to press y/Y or n/N: >
endif
endfunc

call popup_dialog('Continue? y/n', *{
call popup_dialog('Continue? y/n', ~{
\ filter: 'popup_filter_yesno',
\ callback: 'MyDialogHandler',
\ })
<
*popup_menu-shortcut-example*
Extend popup_filter_menu() with shortcut keys: >

call popup_menu(['Save', 'Cancel', 'Discard'], *{
call popup_menu(['Save', 'Cancel', 'Discard'], ~{
\ filter: 'MyMenuFilter',
\ callback: 'MyMenuHandler',
\ })
@@ -781,7 +781,7 @@ Example for using a popup window for 'ballooneval': >
endif
call popup_close(s:winid)
endif
let s:winid = popup_beval(v:beval_text, *{mousemoved: 'word'})
let s:winid = popup_beval(v:beval_text, ~{mousemoved: 'word'})
let s:last_text = v:beval_text
return ''
endfunc
@@ -812,7 +812,7 @@ this example simulated with a timer callback: >
endfunc

func ShowPopup(id)
let s:winid = popup_beval(s:balloonText, *{mousemoved: 'word'})
let s:winid = popup_beval(s:balloonText, ~{mousemoved: 'word'})
endfunc
<

@@ -4266,7 +4266,7 @@ eval6(
for (;;)
{
op = **arg;
if ((op != '*' || (*arg)[1] == '{') && op != '/' && op != '%')
if (op != '*' && op != '/' && op != '%')
break;

if (evaluate)
@@ -4392,7 +4392,7 @@ eval6(
* (expression) nested expression
* [expr, expr] List
* {key: val, key: val} Dictionary
* *{key: val, key: val} Dictionary with literal keys
* ~{key: val, key: val} Dictionary with literal keys
*
* Also handle:
* ! in front logical NOT
@@ -4577,9 +4577,9 @@ eval7(
break;

/*
* Dictionary: *{key: val, key: val}
* Dictionary: ~{key: val, key: val}
*/
case '*': if ((*arg)[1] == '{')
case '~': if ((*arg)[1] == '{')
{
++*arg;
ret = dict_get_tv(arg, rettv, evaluate, TRUE);
@@ -6,5 +6,5 @@
|~| @73
|~| @52|o+0#0000001#ffd7ff255|t|h|e|r| |t|a|b| @11
|~+0#4040ff13#ffffff0| @52|a+0#0000001#ffd7ff255| |c+0#ff404010&|o|m@1|e|n|t| +0#0000001&|l|i|n|e| @6
|:+0#0000000#ffffff0|c|a|l@1| |p|o|p|u|p|_|m|o|v|e|(|p|o|p|u|p|w|i|n|,| |*|{|l|i|n|e|:| |7|,| |c|o|l|:| |5@1|}|)| @6|t+0#0000001#ffd7ff255|h|i|s| |l|i|n|e| |w|i|l@1| |n|o|t| |f|i
|:+0#0000000#ffffff0| @52|t+0#0000001#ffd7ff255|h|i|s| |l|i|n|e| |w|i|l@1| |n|o|t| |f|i
| +0#0000000#ffffff0@53|t+0#0000001#ffd7ff255| |h|e|r|e| @14
@@ -10,4 +10,4 @@
|1|2|3|4|5|6|7|8|9|1|0|║+0#0000001#ffd7ff255| @10|1+0#0000000#ffffff0|7|1|8|1|9|2|0|2|1|2@2|3|2|4|2|5|2|6|2|7|2|8|2|9|3|0|3|1|3|2|3@2|4|3|5|3|6|3|7|3|8|3|9|4|0|4|1|4|2
|1|2|3|4|5|6|7|8|9|1|0|╚+0#0000001#ffd7ff255|═|1+0#0000000#ffffff0|2|1|═+0#0000001#ffd7ff255@4|1+0#0000000#ffffff0|6|1|7|═+0#0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|1|7|1|8|1|9|2|0|2|1|2@2|3|2|4|2|5|║+0#0000001#ffd7ff255| @4|2+0#0000000#ffffff0|9|3| +0#0000001#ffd7ff255@6|║|4+0#0000000#ffffff0|3|5|3|6|3|7|3|8|3|9|4|0|4|1|4|2
|:|c|t+0&#e0e0e08|h|l+0&#ffffff0| |p|l+0&#e0e0e08|i|n|e| |m+0&#ffffff0|o|v|e|(|w|i|n|i|d|b|,| |*|{|p|o|s|:| |'|t|o|p|l|e|f|t|'|║+0#0000001#ffd7ff255| |j|u|s|t| +0#0000000#ffffff0|4|2|e+0#0000001#ffd7ff255| |l|i|n|e| |║|,+0#0000000#ffffff0|1| @10|T|o|p|
|:| |t+0&#e0e0e08|h| +0&#ffffff0@2|l+0&#e0e0e08|i|n|e| | +0&#ffffff0@28|║+0#0000001#ffd7ff255| |j|u|s|t| +0#0000000#ffffff0@2|e+0#0000001#ffd7ff255| |l|i|n|e| |║|,+0#0000000#ffffff0|1| @10|T|o|p|
@@ -7,4 +7,4 @@
|7| @31|f+0#0000001#ffd7ff255|i|v|e| @3| +0#0000000#a8a8a8255| +0&#ffffff0@32
|8| @73
|9| @73
|:|c|a|l@1| |p|o|p|u|p|_|s|e|t|o|p|t|i|o|n|s|(|w|i|n|i|d|,| |*|{|f|i|r|s|t|l|i|n|e|:| |2|}|)| @10|1|,|1| @10|T|o|p|
|:| @55|1|,|1| @10|T|o|p|
@@ -7,4 +7,4 @@
|7| @31|n+0#0000001#ffd7ff255|i|n|e| @3| +0#0000000#0000001| +0&#ffffff0@32
|8| @73
|9| @73
|:|c|a|l@1| |p|o|p|u|p|_|s|e|t|o|p|t|i|o|n|s|(|w|i|n|i|d|,| |*|{|f|i|r|s|t|l|i|n|e|:| |6|}|)| @10|1|,|1| @10|T|o|p|
|:| @55|1|,|1| @10|T|o|p|
@@ -7,4 +7,4 @@
|7| @73
|8| @73
|9| @73
|:|c|a|l@1| |p|o|p|u|p|_|s|e|t|o|p|t|i|o|n|s|(|w|i|n|i|d|,| |*|{|f|i|r|s|t|l|i|n|e|:| |9|}|)| @10|1|,|1| @10|T|o|p|
|:| @55|1|,|1| @10|T|o|p|
@@ -281,8 +281,11 @@ func Test_dict_func_remove_in_use()
endfunc

func Test_dict_literal_keys()
call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, *{one: 1, two2: 2, 3three: 3, 44: 4},)
call assert_equal('2 3', trim(execute('echo 2 *{blue: 3}.blue')))
call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, ~{one: 1, two2: 2, 3three: 3, 44: 4},)

" why *{} cannot be used
let blue = 'blue'
call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
endfunc

" Nasty: deepcopy() dict that refers to itself (fails when noref used)

0 comments on commit b8be54d

Please sign in to comment.
You can’t perform that action at this time.