To: vim_dev@googlegroups.com Subject: Patch 8.2.2620 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2620 Problem: Vim9: Using #{ for a dictionary gives strange errors. Solution: Give an error when using #{ for a comment after a command. Files: src/vim9compile.c, src/vim9script.c, src/proto/vim9script.pro, src/errors.h, src/testdir/test_vim9_expr.vim, src/testdir/test_vim9_script.vim *** ../vim-8.2.2619/src/vim9compile.c 2021-03-17 20:56:33.649085754 +0100 --- src/vim9compile.c 2021-03-18 21:28:15.669791847 +0100 *************** *** 1546,1552 **** isn->isn_arg.funcref.fr_func = ufunc->uf_dfunc_idx; cctx->ctx_has_closure = 1; ! // if the referenced function is a closure, it may use items further up in // the nested context, including this one. if (ufunc->uf_flags & FC_CLOSURE) cctx->ctx_ufunc->uf_flags |= FC_CLOSURE; --- 1546,1552 ---- isn->isn_arg.funcref.fr_func = ufunc->uf_dfunc_idx; cctx->ctx_has_closure = 1; ! // If the referenced function is a closure, it may use items further up in // the nested context, including this one. if (ufunc->uf_flags & FC_CLOSURE) cctx->ctx_ufunc->uf_flags |= FC_CLOSURE; *************** *** 2401,2406 **** --- 2401,2408 ---- if (line != NULL) { p = skipwhite(line); + if (vim9_bad_comment(p)) + return NULL; if (*p != NUL && !vim9_comment_start(p)) return p; } *************** *** 2465,2470 **** --- 2467,2474 ---- may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx) { *arg = skipwhite(whitep); + if (vim9_bad_comment(*arg)) + return FAIL; if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg))) { char_u *next = next_line_from_context(cctx, TRUE); *************** *** 4277,4286 **** if (!eval_isnamec1(**arg)) { ! if (ends_excmd(*skipwhite(*arg))) ! semsg(_(e_empty_expression_str), *arg); ! else ! semsg(_(e_name_expected_str), *arg); return FAIL; } --- 4281,4293 ---- if (!eval_isnamec1(**arg)) { ! if (!vim9_bad_comment(*arg)) ! { ! if (ends_excmd(*skipwhite(*arg))) ! semsg(_(e_empty_expression_str), *arg); ! else ! semsg(_(e_name_expected_str), *arg); ! } return FAIL; } *************** *** 8297,8302 **** --- 8304,8311 ---- semsg(_(e_trailing_arg), line); goto erret; } + else if (line != NULL && vim9_bad_comment(skipwhite(line))) + goto erret; else { line = next_line_from_context(&cctx, FALSE); *** ../vim-8.2.2619/src/vim9script.c 2021-03-13 21:07:17.742458250 +0100 --- src/vim9script.c 2021-03-18 21:15:12.356378094 +0100 *************** *** 113,124 **** } /* ! * Return TRUE if "p" points at a "#". Does not check for white space. */ int vim9_comment_start(char_u *p) { ! return p[0] == '#'; } #if defined(FEAT_EVAL) || defined(PROTO) --- 113,141 ---- } /* ! * Give an error message if "p" points at "#{" and return TRUE. ! * This avoids that using a legacy style #{} dictionary leads to difficult to ! * understand errors. ! */ ! int ! vim9_bad_comment(char_u *p) ! { ! if (p[0] == '#' && p[1] == '{') ! { ! emsg(_(e_cannot_use_hash_curly_to_start_comment)); ! return TRUE; ! } ! return FALSE; ! } ! ! /* ! * Return TRUE if "p" points at a "#" not followed by '{'. ! * Does not check for white space. */ int vim9_comment_start(char_u *p) { ! return p[0] == '#' && p[1] != '{'; } #if defined(FEAT_EVAL) || defined(PROTO) *** ../vim-8.2.2619/src/proto/vim9script.pro 2021-03-13 20:57:15.859515065 +0100 --- src/proto/vim9script.pro 2021-03-18 20:59:24.863583856 +0100 *************** *** 2,7 **** --- 2,8 ---- int in_vim9script(void); void ex_vim9script(exarg_T *eap); int not_in_vim9(exarg_T *eap); + int vim9_bad_comment(char_u *p); int vim9_comment_start(char_u *p); void ex_export(exarg_T *eap); void free_imports_and_script_vars(int sid); *** ../vim-8.2.2619/src/errors.h 2021-03-13 20:57:15.859515065 +0100 --- src/errors.h 2021-03-18 20:58:38.311747367 +0100 *************** *** 375,377 **** --- 375,379 ---- INIT(= N_("E1168: Argument already declared in the script: %s")); EXTERN char e_import_as_name_not_supported_here[] INIT(= N_("E1169: 'import * as {name}' not supported here")); + EXTERN char e_cannot_use_hash_curly_to_start_comment[] + INIT(= N_("E1170: 'Cannot use #{ to start a comment")); *** ../vim-8.2.2619/src/testdir/test_vim9_expr.vim 2021-03-14 18:38:50.016676652 +0100 --- src/testdir/test_vim9_expr.vim 2021-03-18 21:29:00.577644048 +0100 *************** *** 2159,2166 **** CheckDefAndScriptSuccess(lines) # legacy syntax doesn't work ! CheckDefFailure(["var x = #{key: 8}"], 'E1097:', 3) ! CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1097:', 3) CheckDefFailure(["var x = {a:8}"], 'E1069:', 1) CheckDefFailure(["var x = {a : 8}"], 'E1068:', 1) --- 2159,2168 ---- CheckDefAndScriptSuccess(lines) # legacy syntax doesn't work ! CheckDefFailure(["var x = #{key: 8}"], 'E1170:', 1) ! CheckDefFailure(["var x = 'a' #{a: 1}"], 'E1170:', 1) ! CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1170:', 1) ! CheckDefFailure(["var x = true ? #{a: 1}"], 'E1170:', 1) CheckDefFailure(["var x = {a:8}"], 'E1069:', 1) CheckDefFailure(["var x = {a : 8}"], 'E1068:', 1) *** ../vim-8.2.2619/src/testdir/test_vim9_script.vim 2021-03-17 17:45:55.353935904 +0100 --- src/testdir/test_vim9_script.vim 2021-03-18 21:30:27.821357022 +0100 *************** *** 2452,2458 **** assert_equal('1_3_', result) var s = '' ! while s == 'x' #{comment} endwhile enddef --- 2452,2458 ---- assert_equal('1_3_', result) var s = '' ! while s == 'x' # {comment} endwhile enddef *** ../vim-8.2.2619/src/version.c 2021-03-17 21:29:25.497532653 +0100 --- src/version.c 2021-03-18 21:36:35.436148202 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2620, /**/ -- I learned the customs and mannerisms of engineers by observing them, much the way Jane Goodall learned about the great apes, but without the hassle of grooming. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///