To: vim_dev@googlegroups.com Subject: Patch 8.2.3877 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3877 Problem: Function does not abort after a type error in compare Solution: Check getting number fails. (closes #9384) Files: src/typval.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.3876/src/typval.c 2021-12-19 12:32:54.066426460 +0000 --- src/typval.c 2021-12-22 21:22:34.141669135 +0000 *************** *** 297,304 **** } #if defined(FEAT_FLOAT) || defined(PROTO) ! float_T ! tv_get_float(typval_T *varp) { switch (varp->v_type) { --- 297,304 ---- } #if defined(FEAT_FLOAT) || defined(PROTO) ! static float_T ! tv_get_float_chk(typval_T *varp, int *error) { switch (varp->v_type) { *************** *** 347,354 **** --- 347,362 ---- internal_error_no_abort("tv_get_float(UNKNOWN)"); break; } + if (error != NULL) + *error = TRUE; return 0; } + + float_T + tv_get_float(typval_T *varp) + { + return tv_get_float_chk(varp, NULL); + } #endif /* *************** *** 1185,1193 **** && type != EXPR_MATCH && type != EXPR_NOMATCH) { float_T f1, f2; ! f1 = tv_get_float(tv1); ! f2 = tv_get_float(tv2); n1 = FALSE; switch (type) { --- 1193,1208 ---- && type != EXPR_MATCH && type != EXPR_NOMATCH) { float_T f1, f2; + int error = FALSE; ! f1 = tv_get_float_chk(tv1, &error); ! if (!error) ! f2 = tv_get_float_chk(tv2, &error); ! if (error) ! { ! clear_tv(tv1); ! return FAIL; ! } n1 = FALSE; switch (type) { *************** *** 1211,1218 **** else if ((tv1->v_type == VAR_NUMBER || tv2->v_type == VAR_NUMBER) && type != EXPR_MATCH && type != EXPR_NOMATCH) { ! n1 = tv_get_number(tv1); ! n2 = tv_get_number(tv2); switch (type) { case EXPR_IS: --- 1226,1241 ---- else if ((tv1->v_type == VAR_NUMBER || tv2->v_type == VAR_NUMBER) && type != EXPR_MATCH && type != EXPR_NOMATCH) { ! int error = FALSE; ! ! n1 = tv_get_number_chk(tv1, &error); ! if (!error) ! n2 = tv_get_number_chk(tv2, &error); ! if (error) ! { ! clear_tv(tv1); ! return FAIL; ! } switch (type) { case EXPR_IS: *** ../vim-8.2.3876/src/testdir/test_vim9_expr.vim 2021-12-19 18:33:17.325954806 +0000 --- src/testdir/test_vim9_expr.vim 2021-12-22 21:24:04.025986452 +0000 *************** *** 675,680 **** --- 675,710 ---- CheckDefExecAndScriptFailure(["var x: any = true", 'echo x == ""'], 'E1072: Cannot compare bool with string', 2) CheckDefExecAndScriptFailure(["var x: any = 99", 'echo x == true'], ['E1138', 'E1072:'], 2) CheckDefExecAndScriptFailure(["var x: any = 'a'", 'echo x == 99'], ['E1030:', 'E1072:'], 2) + + lines =<< trim END + vim9script + var n: any = 2 + def Compare() + eval n == '3' + g:notReached = false + enddef + g:notReached = true + Compare() + END + CheckScriptFailure(lines, 'E1030: Using a String as a Number: "3"') + assert_true(g:notReached) + + if has('float') + lines =<< trim END + vim9script + var n: any = 2.2 + def Compare() + eval n == '3' + g:notReached = false + enddef + g:notReached = true + Compare() + END + CheckScriptFailure(lines, 'E892: Using a String as a Float') + assert_true(g:notReached) + endif + + unlet g:notReached enddef def Test_expr4_wrong_type() *** ../vim-8.2.3876/src/version.c 2021-12-22 20:55:26.309070326 +0000 --- src/version.c 2021-12-22 21:26:06.662309139 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3877, /**/ -- Do not trust atoms, they make up everything. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///