vim-patch:8.2.{1949,2781} (#22451)

vim-patch:8.2.2781: add() silently skips when adding to null list or blob

Problem:    Add() silently skips when adding to null list or blob.
Solution:   Give an error in Vim9 script.  Allocate blob when it is NULL like
            with list and dict.

b7c21afef1

Do not implicitly change a NULL blob/dict/list to an empty one.

N/A patches for version.c:

vim-patch:8.2.1949: Vim9: using extend() on null dict is silently ignored

Problem:    Vim9: using extend() on null dict is silently ignored.
Solution:   Give an error message.  Initialize a dict variable with an empty
            dictionary. (closes vim/vim#7251)

348be7ed07

N/A because Nvim's current behavior is an error message as a locked
list/dict, which is more consistent. Ref #4615.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2023-03-01 23:23:39 +08:00 committed by GitHub
parent 896d672736
commit f25d126b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -317,27 +317,59 @@ func Test_blob_for_loop()
endfunc
func Test_blob_concatenate()
let b = 0z0011
let b += 0z2233
call assert_equal(0z00112233, b)
let lines =<< trim END
VAR b = 0z0011
LET b += 0z2233
call assert_equal(0z00112233, b)
call assert_fails('let b += "a"')
call assert_fails('let b += 88')
LET b = 0zDEAD + 0zBEEF
call assert_equal(0zDEADBEEF, b)
END
call CheckLegacyAndVim9Success(lines)
let b = 0zDEAD + 0zBEEF
call assert_equal(0zDEADBEEF, b)
let lines =<< trim END
VAR b = 0z0011
LET b += "a"
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
let lines =<< trim END
VAR b = 0z0011
LET b += 88
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
endfunc
func Test_blob_add()
let lines =<< trim END
VAR b = 0z0011
call add(b, 0x22)
call assert_equal(0z001122, b)
END
call CheckLegacyAndVim9Success(lines)
" Only works in legacy script
let b = 0z0011
call add(b, 0x22)
call assert_equal(0z001122, b)
call add(b, '51')
call assert_equal(0z00112233, b)
call assert_equal(0z001133, b)
call assert_equal(1, add(v:_null_blob, 0x22))
call assert_fails('call add(b, [9])', 'E745:')
call assert_fails('call add("", 0x01)', 'E897:')
let lines =<< trim END
VAR b = 0z0011
call add(b, [9])
END
call CheckLegacyAndVim9Failure(lines, ['E745:', 'E1012:', 'E745:'])
let lines =<< trim END
VAR b = 0z0011
call add("", 0x01)
END
call CheckLegacyAndVim9Failure(lines, 'E897:')
let lines =<< trim END
add(v:_null_blob, 0x22)
END
call CheckDefExecAndScriptFailure(lines, 'E1131:')
endfunc
func Test_blob_empty()