Mercurial > vim
changeset 25561:164cef0bc7ab v8.2.3317
patch 8.2.3317: Vim9: No error for missing white space before return type
Commit: https://github.com/vim/vim/commit/33ea9fd4d849324f1e958cc669987a51cf0baded
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 8 19:07:37 2021 +0200
patch 8.2.3317: Vim9: No error for missing white space before return type
Problem: Vim9: No error for missing white space before return type.
Solution: Check for white space. (closes https://github.com/vim/vim/issues/8733)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 08 Aug 2021 19:15:04 +0200 |
parents | 143d7ea8f339 |
children | e9b92f1c2358 |
files | src/testdir/test_vim9_func.vim src/userfunc.c src/version.c |
diffstat | 3 files changed, 31 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -1429,6 +1429,27 @@ def Test_return_type_wrong() 'defcompile'], 'E1003:') delfunc! g:Func + CheckScriptFailure([ + 'def Func():number', + 'return 123', + 'enddef', + 'defcompile'], 'E1069:') + delfunc! g:Func + + CheckScriptFailure([ + 'def Func() :number', + 'return 123', + 'enddef', + 'defcompile'], 'E1059:') + delfunc! g:Func + + CheckScriptFailure([ + 'def Func() : number', + 'return 123', + 'enddef', + 'defcompile'], 'E1059:') + delfunc! g:Func + CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') delfunc! g:Func CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -4066,8 +4066,15 @@ define_function(exarg_T *eap, char_u *na if (eap->cmdidx == CMD_def) { // find the return type: :def Func(): type - if (*p == ':') + if (*skipwhite(p) == ':') { + if (*p != ':') + { + semsg(_(e_no_white_space_allowed_before_colon_str), p); + p = skipwhite(p); + } + else if (!IS_WHITE_OR_NUL(p[1])) + semsg(_(e_white_space_required_after_str_str), ":", p); ret_type = skipwhite(p + 1); p = skip_type(ret_type, FALSE); if (p > ret_type)