comparison src/testdir/test_vim9_assign.vim @ 30217:e0cb5fb44859 v9.0.0444

patch 9.0.0444: trying to declare g:variable gives confusing error Commit: https://github.com/vim/vim/commit/9510d22463055f56548ff461ccbc54caa1ba1a2f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 11 15:14:05 2022 +0100 patch 9.0.0444: trying to declare g:variable gives confusing error Problem: Trying to declare g:variable gives confusing error. Solution: Give a better error message. (closes https://github.com/vim/vim/issues/11108)
author Bram Moolenaar <Bram@vim.org>
date Sun, 11 Sep 2022 16:15:04 +0200
parents 13b02c1ea0f7
children 029c59bf78f1
comparison
equal deleted inserted replaced
30216:cafa3e83fdde 30217:e0cb5fb44859
1595 1595
1596 assert_fails('s/^/\=g:Mess()/n', 'E794:') 1596 assert_fails('s/^/\=g:Mess()/n', 'E794:')
1597 v9.CheckDefFailure(['var name: dict<number'], 'E1009:') 1597 v9.CheckDefFailure(['var name: dict<number'], 'E1009:')
1598 1598
1599 v9.CheckDefFailure(['w:foo: number = 10'], 1599 v9.CheckDefFailure(['w:foo: number = 10'],
1600 'E488: Trailing characters: : number = 1') 1600 'E1016: Cannot declare a window variable: w:foo')
1601 v9.CheckDefFailure(['t:foo: bool = true'], 1601 v9.CheckDefFailure(['t:foo: bool = true'],
1602 'E488: Trailing characters: : bool = true') 1602 'E1016: Cannot declare a tab variable: t:foo')
1603 v9.CheckDefFailure(['b:foo: string = "x"'], 1603 v9.CheckDefFailure(['b:foo: string = "x"'],
1604 'E488: Trailing characters: : string = "x"') 1604 'E1016: Cannot declare a buffer variable: b:foo')
1605 v9.CheckDefFailure(['g:foo: number = 123'], 1605 v9.CheckDefFailure(['g:foo: number = 123'],
1606 'E488: Trailing characters: : number = 123') 1606 'E1016: Cannot declare a global variable: g:foo')
1607
1608 v9.CheckScriptFailure(['vim9script', 'w:foo: number = 123'],
1609 'E1304: Cannot use type with this variable: w:foo:')
1610 v9.CheckScriptFailure(['vim9script', 't:foo: number = 123'],
1611 'E1304: Cannot use type with this variable: t:foo:')
1612 v9.CheckScriptFailure(['vim9script', 'b:foo: number = 123'],
1613 'E1304: Cannot use type with this variable: b:foo:')
1614 v9.CheckScriptFailure(['vim9script', 'g:foo: number = 123'],
1615 'E1304: Cannot use type with this variable: g:foo:')
1616
1617 v9.CheckScriptFailure(['vim9script', 'const w:FOO: number = 123'],
1618 'E1304: Cannot use type with this variable: w:FOO:')
1619 v9.CheckScriptFailure(['vim9script', 'const t:FOO: number = 123'],
1620 'E1304: Cannot use type with this variable: t:FOO:')
1621 v9.CheckScriptFailure(['vim9script', 'const b:FOO: number = 123'],
1622 'E1304: Cannot use type with this variable: b:FOO:')
1623 v9.CheckScriptFailure(['vim9script', 'const g:FOO: number = 123'],
1624 'E1304: Cannot use type with this variable: g:FOO:')
1607 enddef 1625 enddef
1608 1626
1609 def Test_assign_list() 1627 def Test_assign_list()
1610 var lines =<< trim END 1628 var lines =<< trim END
1611 var l: list<string> = [] 1629 var l: list<string> = []
1957 final FLIST = [1] 1975 final FLIST = [1]
1958 assert_equal([1], FLIST) 1976 assert_equal([1], FLIST)
1959 FLIST[0] = 11 1977 FLIST[0] = 11
1960 assert_equal([11], FLIST) 1978 assert_equal([11], FLIST)
1961 1979
1962 const g:FOO: number = 321
1963 assert_equal(321, g:FOO)
1964 const g:FOOS = 'gfoos' 1980 const g:FOOS = 'gfoos'
1965 assert_equal('gfoos', g:FOOS) 1981 assert_equal('gfoos', g:FOOS)
1966 final g:FLIST = [2] 1982 final g:FLIST = [2]
1967 assert_equal([2], g:FLIST) 1983 assert_equal([2], g:FLIST)
1968 g:FLIST[0] = 22 1984 g:FLIST[0] = 22
1973 enddef 1989 enddef
1974 SetGlobalConst() 1990 SetGlobalConst()
1975 assert_equal(123, g:globConst) 1991 assert_equal(123, g:globConst)
1976 assert_true(islocked('g:globConst')) 1992 assert_true(islocked('g:globConst'))
1977 1993
1978 const w:FOO: number = 46
1979 assert_equal(46, w:FOO)
1980 const w:FOOS = 'wfoos' 1994 const w:FOOS = 'wfoos'
1981 assert_equal('wfoos', w:FOOS) 1995 assert_equal('wfoos', w:FOOS)
1982 final w:FLIST = [3] 1996 final w:FLIST = [3]
1983 assert_equal([3], w:FLIST) 1997 assert_equal([3], w:FLIST)
1984 w:FLIST[0] = 33 1998 w:FLIST[0] = 33
2013 unlet g:var_uninit 2027 unlet g:var_uninit
2014 unlet g:var_test 2028 unlet g:var_test
2015 unlet g:var_prefixed 2029 unlet g:var_prefixed
2016 unlet g:other_var 2030 unlet g:other_var
2017 unlet g:globConst 2031 unlet g:globConst
2018 unlet g:FOO
2019 unlet g:FOOS 2032 unlet g:FOOS
2020 unlet g:FLIST 2033 unlet g:FLIST
2021 unlet w:FOO
2022 unlet w:FOOS 2034 unlet w:FOOS
2023 unlet w:FLIST 2035 unlet w:FLIST
2024 enddef 2036 enddef
2025 2037
2026 def Test_var_declaration_fails() 2038 def Test_var_declaration_fails()