Mercurial > vim
comparison src/testdir/test_vim9_script.vim @ 20397:c225be44692a v8.2.0753
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Commit: https://github.com/vim/vim/commit/32e351179eacfc84f64cd5029e221582d400bb38
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 14 22:41:15 2020 +0200
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Problem: Vim9: expressions are evaluated in the discovery phase.
Solution: Bail out if an expression is not a constant. Require a type for
declared constants.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 14 May 2020 22:45:04 +0200 |
parents | 680296770464 |
children | d1a54d2bd145 |
comparison
equal
deleted
inserted
replaced
20396:89228c88b5c4 | 20397:c225be44692a |
---|---|
492 vim9script | 492 vim9script |
493 let name: string = 'bob' | 493 let name: string = 'bob' |
494 def Concat(arg: string): string | 494 def Concat(arg: string): string |
495 return name .. arg | 495 return name .. arg |
496 enddef | 496 enddef |
497 let g:result = Concat('bie') | 497 let g:result: string = Concat('bie') |
498 let g:localname = name | 498 let g:localname = name |
499 | 499 |
500 export const CONST = 1234 | 500 export const CONST = 1234 |
501 export let exported = 9876 | 501 export let exported = 9876 |
502 export let exp_name = 'John' | 502 export let exp_name = 'John' |
1631 ]) | 1631 ]) |
1632 | 1632 |
1633 CheckScriptFailure([ | 1633 CheckScriptFailure([ |
1634 'vim9script', | 1634 'vim9script', |
1635 'let g:var = 123', | 1635 'let g:var = 123', |
1636 'unlet g:var# comment', | 1636 'unlet g:var# comment1', |
1637 ], 'E108:') | 1637 ], 'E108:') |
1638 | 1638 |
1639 CheckScriptFailure([ | 1639 CheckScriptFailure([ |
1640 'let g:var = 123', | 1640 'let g:var = 123', |
1641 'unlet g:var # something', | 1641 'unlet g:var # something', |
1642 ], 'E488:') | 1642 ], 'E488:') |
1643 | 1643 |
1644 CheckScriptSuccess([ | 1644 CheckScriptSuccess([ |
1645 'vim9script', | 1645 'vim9script', |
1646 'if 1 # comment', | 1646 'if 1 # comment2', |
1647 ' echo "yes"', | 1647 ' echo "yes"', |
1648 'elseif 2 #comment', | 1648 'elseif 2 #comment', |
1649 ' echo "no"', | 1649 ' echo "no"', |
1650 'endif', | 1650 'endif', |
1651 ]) | 1651 ]) |
1652 | 1652 |
1653 CheckScriptFailure([ | 1653 CheckScriptFailure([ |
1654 'vim9script', | 1654 'vim9script', |
1655 'if 1# comment', | 1655 'if 1# comment3', |
1656 ' echo "yes"', | 1656 ' echo "yes"', |
1657 'endif', | 1657 'endif', |
1658 ], 'E15:') | 1658 ], 'E15:') |
1659 | 1659 |
1660 CheckScriptFailure([ | 1660 CheckScriptFailure([ |
1661 'vim9script', | 1661 'vim9script', |
1662 'if 0 # comment', | 1662 'if 0 # comment4', |
1663 ' echo "yes"', | 1663 ' echo "yes"', |
1664 'elseif 2#comment', | 1664 'elseif 2#comment', |
1665 ' echo "no"', | 1665 ' echo "no"', |
1666 'endif', | 1666 'endif', |
1667 ], 'E15:') | 1667 ], 'E15:') |
1668 | 1668 |
1669 CheckScriptSuccess([ | 1669 CheckScriptSuccess([ |
1670 'vim9script', | 1670 'vim9script', |
1671 'let # comment', | 1671 'let v = 1 # comment5', |
1672 ]) | 1672 ]) |
1673 | 1673 |
1674 CheckScriptFailure([ | 1674 CheckScriptFailure([ |
1675 'vim9script', | 1675 'vim9script', |
1676 'let# comment', | 1676 'let v = 1# comment6', |
1677 ], 'E121:') | 1677 ], 'E15:') |
1678 | 1678 |
1679 CheckScriptSuccess([ | 1679 CheckScriptFailure([ |
1680 'vim9script', | 1680 'vim9script', |
1681 'let v:version # comment', | 1681 'let v:version', |
1682 ]) | 1682 ], 'E1091:') |
1683 | |
1684 CheckScriptFailure([ | |
1685 'vim9script', | |
1686 'let v:version# comment', | |
1687 ], 'E121:') | |
1688 | 1683 |
1689 CheckScriptSuccess([ | 1684 CheckScriptSuccess([ |
1690 'vim9script', | 1685 'vim9script', |
1691 'new' | 1686 'new' |
1692 'call setline(1, ["# define pat", "last"])', | 1687 'call setline(1, ["# define pat", "last"])', |
1717 writefile(lines, 'Xfinished') | 1712 writefile(lines, 'Xfinished') |
1718 source Xfinished | 1713 source Xfinished |
1719 assert_equal('two', g:res) | 1714 assert_equal('two', g:res) |
1720 | 1715 |
1721 unlet g:res | 1716 unlet g:res |
1717 delete('Xfinished') | |
1718 enddef | |
1719 | |
1720 def Test_let_func_call() | |
1721 let lines =<< trim END | |
1722 vim9script | |
1723 func GetValue() | |
1724 if exists('g:count') | |
1725 let g:count += 1 | |
1726 else | |
1727 let g:count = 1 | |
1728 endif | |
1729 return 'this' | |
1730 endfunc | |
1731 let val: string = GetValue() | |
1732 END | |
1733 writefile(lines, 'Xfinished') | |
1734 source Xfinished | |
1735 assert_equal(1, g:count) | |
1736 | |
1737 unlet g:count | |
1738 delete('Xfinished') | |
1739 enddef | |
1740 | |
1741 def Test_let_missing_type() | |
1742 let lines =<< trim END | |
1743 vim9script | |
1744 func GetValue() | |
1745 return 'this' | |
1746 endfunc | |
1747 let val = GetValue() | |
1748 END | |
1749 writefile(lines, 'Xfinished') | |
1750 assert_fails('source Xfinished', 'E1091:') | |
1751 | |
1722 delete('Xfinished') | 1752 delete('Xfinished') |
1723 enddef | 1753 enddef |
1724 | 1754 |
1725 " Keep this last, it messes up highlighting. | 1755 " Keep this last, it messes up highlighting. |
1726 def Test_substitute_cmd() | 1756 def Test_substitute_cmd() |