To: vim_dev@googlegroups.com Subject: Patch 8.2.1419 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1419 Problem: Vim9: not operator applied too early. Solution: Implement the "numeric_only" argument. (closes #6680) Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.1418/src/vim9compile.c 2020-08-09 19:02:46.281077049 +0200 --- src/vim9compile.c 2020-08-10 23:04:38.062127342 +0200 *************** *** 2723,2733 **** /* * Apply leading '!', '-' and '+' to constant "rettv". */ static int ! apply_leader(typval_T *rettv, char_u *start, char_u *end) { ! char_u *p = end; // this works from end to start while (p > start) --- 2723,2734 ---- /* * Apply leading '!', '-' and '+' to constant "rettv". + * When "numeric_only" is TRUE do not apply '!'. */ static int ! apply_leader(typval_T *rettv, int numeric_only, char_u *start, char_u **end) { ! char_u *p = *end; // this works from end to start while (p > start) *************** *** 2762,2767 **** --- 2763,2773 ---- rettv->vval.v_number = val; } } + else if (numeric_only) + { + ++p; + break; + } else { int v = tv2bool(rettv); *************** *** 2772,2777 **** --- 2778,2784 ---- rettv->vval.v_number = v ? VVAL_FALSE : VVAL_TRUE; } } + *end = p; return OK; } *************** *** 2860,2870 **** /* * Compile code to apply '-', '+' and '!'. */ static int ! compile_leader(cctx_T *cctx, char_u *start, char_u *end) { ! char_u *p = end; // this works from end to start while (p > start) --- 2867,2878 ---- /* * Compile code to apply '-', '+' and '!'. + * When "numeric_only" is TRUE do not apply '!'. */ static int ! compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end) { ! char_u *p = *end; // this works from end to start while (p > start) *************** *** 2890,2895 **** --- 2898,2908 ---- if (isn == NULL) return FAIL; } + else if (numeric_only) + { + ++p; + break; + } else { int invert = TRUE; *************** *** 2903,2908 **** --- 2916,2922 ---- return FAIL; } } + *end = p; return OK; } *************** *** 2914,2923 **** compile_subscript( char_u **arg, cctx_T *cctx, ! char_u **start_leader, ! char_u *end_leader, ppconst_T *ppconst) { for (;;) { char_u *p = skipwhite(*arg); --- 2928,2939 ---- compile_subscript( char_u **arg, cctx_T *cctx, ! char_u *start_leader, ! char_u **end_leader, ppconst_T *ppconst) { + char_u *name_start = *end_leader; + for (;;) { char_u *p = skipwhite(*arg); *************** *** 2959,2965 **** *arg = skipwhite(p + 1); if (compile_arguments(arg, cctx, &argcount) == FAIL) return FAIL; ! if (generate_PCALL(cctx, argcount, end_leader, type, TRUE) == FAIL) return FAIL; } else if (*p == '-' && p[1] == '>') --- 2975,2981 ---- *arg = skipwhite(p + 1); if (compile_arguments(arg, cctx, &argcount) == FAIL) return FAIL; ! if (generate_PCALL(cctx, argcount, name_start, type, TRUE) == FAIL) return FAIL; } else if (*p == '-' && p[1] == '>') *************** *** 2972,2980 **** // something->method() // Apply the '!', '-' and '+' first: // -1.0->func() works like (-1.0)->func() ! if (compile_leader(cctx, *start_leader, end_leader) == FAIL) return FAIL; - *start_leader = end_leader; // don't apply again later p += 2; *arg = skipwhite(p); --- 2988,2995 ---- // something->method() // Apply the '!', '-' and '+' first: // -1.0->func() works like (-1.0)->func() ! if (compile_leader(cctx, TRUE, start_leader, end_leader) == FAIL) return FAIL; p += 2; *arg = skipwhite(p); *************** *** 3329,3341 **** if (rettv->v_type != VAR_UNKNOWN && used_before == ppconst->pp_used) { ! // apply the '!', '-' and '+' before the constant ! if (apply_leader(rettv, start_leader, end_leader) == FAIL) { clear_tv(rettv); return FAIL; } - start_leader = end_leader; // don't apply again below if (cctx->ctx_skip == SKIP_YES) clear_tv(rettv); --- 3344,3355 ---- if (rettv->v_type != VAR_UNKNOWN && used_before == ppconst->pp_used) { ! // apply the '-' and '+' before the constant, but not '!' ! if (apply_leader(rettv, TRUE, start_leader, &end_leader) == FAIL) { clear_tv(rettv); return FAIL; } if (cctx->ctx_skip == SKIP_YES) clear_tv(rettv); *************** *** 3373,3390 **** // Handle following "[]", ".member", etc. // Then deal with prefixed '-', '+' and '!', if not done already. ! if (compile_subscript(arg, cctx, &start_leader, end_leader, ppconst) == FAIL) return FAIL; if (ppconst->pp_used > 0) { // apply the '!', '-' and '+' before the constant rettv = &ppconst->pp_tv[ppconst->pp_used - 1]; ! if (apply_leader(rettv, start_leader, end_leader) == FAIL) return FAIL; return OK; } ! if (compile_leader(cctx, start_leader, end_leader) == FAIL) return FAIL; return OK; } --- 3387,3404 ---- // Handle following "[]", ".member", etc. // Then deal with prefixed '-', '+' and '!', if not done already. ! if (compile_subscript(arg, cctx, start_leader, &end_leader, ppconst) == FAIL) return FAIL; if (ppconst->pp_used > 0) { // apply the '!', '-' and '+' before the constant rettv = &ppconst->pp_tv[ppconst->pp_used - 1]; ! if (apply_leader(rettv, FALSE, start_leader, &end_leader) == FAIL) return FAIL; return OK; } ! if (compile_leader(cctx, FALSE, start_leader, &end_leader) == FAIL) return FAIL; return OK; } *** ../vim-8.2.1418/src/testdir/test_vim9_expr.vim 2020-08-10 22:40:53.322652515 +0200 --- src/testdir/test_vim9_expr.vim 2020-08-10 23:05:37.905937458 +0200 *************** *** 1744,1750 **** assert_equal('yes', 'yes'->Echo()) assert_equal('yes', 'yes' ->s:Echo4Arg()) ! assert_equal(1, !range(5)->empty()) assert_equal([0, 1, 2], --3->range()) call CheckDefFailure(["let x = 'yes'->Echo"], 'E107:') --- 1744,1750 ---- assert_equal('yes', 'yes'->Echo()) assert_equal('yes', 'yes' ->s:Echo4Arg()) ! assert_equal(true, !range(5)->empty()) assert_equal([0, 1, 2], --3->range()) call CheckDefFailure(["let x = 'yes'->Echo"], 'E107:') *************** *** 1782,1787 **** --- 1782,1790 ---- assert_equal(true, !test_void()) assert_equal(true, !test_unknown()) + + assert_equal(false, ![1, 2, 3]->reverse()) + assert_equal(true, ![]->reverse()) END CheckDefSuccess(lines) CheckScriptSuccess(['vim9script'] + lines) *** ../vim-8.2.1418/src/version.c 2020-08-10 22:40:53.322652515 +0200 --- src/version.c 2020-08-10 23:06:57.005689374 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1419, /**/ -- Very funny, Scotty. Now beam down my clothes. /// 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 ///