To: vim_dev@googlegroups.com Subject: Patch 8.2.3310 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3310 Problem: Vim9: unpack assignment does not mention source of type error. Solution: Mention the argument number. (closes #8719) Files: src/vim9compile.c, src/testdir/test_vim9_assign.vim, src/testdir/test_vim9_disassemble.vim *** ../vim-8.2.3309/src/vim9compile.c 2021-08-07 15:05:44.707105779 +0200 --- src/vim9compile.c 2021-08-07 16:14:27.307583449 +0200 *************** *** 1039,1056 **** * If "actual_is_const" is TRUE then the type won't change at runtime, do not * generate a TYPECHECK. */ ! int ! need_type( type_T *actual, type_T *expected, int offset, ! int arg_idx, cctx_T *cctx, int silent, int actual_is_const) { - where_T where = WHERE_INIT; - if (expected == &t_bool && actual != &t_bool && (actual->tt_flags & TTFLAG_BOOL_OK)) { --- 1039,1054 ---- * If "actual_is_const" is TRUE then the type won't change at runtime, do not * generate a TYPECHECK. */ ! static int ! need_type_where( type_T *actual, type_T *expected, int offset, ! where_T where, cctx_T *cctx, int silent, int actual_is_const) { if (expected == &t_bool && actual != &t_bool && (actual->tt_flags & TTFLAG_BOOL_OK)) { *************** *** 1060,1066 **** return OK; } - where.wt_index = arg_idx; if (check_type(expected, actual, FALSE, where) == OK) return OK; --- 1058,1063 ---- *************** *** 1069,1083 **** if ((!actual_is_const || actual == &t_any) && use_typecheck(actual, expected)) { ! generate_TYPECHECK(cctx, expected, offset, arg_idx); return OK; } if (!silent) ! arg_type_mismatch(expected, actual, arg_idx); return FAIL; } /* * Check that the top of the type stack has a type that can be used as a * condition. Give an error and return FAIL if not. --- 1066,1097 ---- if ((!actual_is_const || actual == &t_any) && use_typecheck(actual, expected)) { ! generate_TYPECHECK(cctx, expected, offset, where.wt_index); return OK; } if (!silent) ! type_mismatch_where(expected, actual, where); return FAIL; } + int + need_type( + type_T *actual, + type_T *expected, + int offset, + int arg_idx, + cctx_T *cctx, + int silent, + int actual_is_const) + { + where_T where = WHERE_INIT; + + where.wt_index = arg_idx; + return need_type_where(actual, expected, offset, where, + cctx, silent, actual_is_const); + } + /* * Check that the top of the type stack has a type that can be used as a * condition. Give an error and return FAIL if not. *************** *** 7004,7017 **** else if (*op == '=') { type_T *use_type = lhs.lhs_lvar->lv_type; // Without operator check type here, otherwise below. // Use the line number of the assignment. SOURCING_LNUM = start_lnum; if (lhs.lhs_has_index) use_type = lhs.lhs_member_type; ! if (need_type(rhs_type, use_type, -1, 0, cctx, ! FALSE, is_const) == FAIL) goto theend; } } --- 7018,7034 ---- else if (*op == '=') { type_T *use_type = lhs.lhs_lvar->lv_type; + where_T where = WHERE_INIT; // Without operator check type here, otherwise below. // Use the line number of the assignment. SOURCING_LNUM = start_lnum; + where.wt_index = var_count > 0 ? var_idx + 1 : 0; + where.wt_variable = var_count > 0; if (lhs.lhs_has_index) use_type = lhs.lhs_member_type; ! if (need_type_where(rhs_type, use_type, -1, where, ! cctx, FALSE, is_const) == FAIL) goto theend; } } *** ../vim-8.2.3309/src/testdir/test_vim9_assign.vim 2021-08-05 19:01:12.294746361 +0200 --- src/testdir/test_vim9_assign.vim 2021-08-07 16:20:07.470632146 +0200 *************** *** 414,419 **** --- 414,435 ---- [x, y] = g:values END CheckDefExecAndScriptFailure(lines, 'E1163: Variable 2: type mismatch, expected string but got number') + + lines =<< trim END + var x: number + var y: number + var z: string + [x, y, z] = [1, 2, 3] + END + CheckDefAndScriptFailure(lines, 'E1163: Variable 3: type mismatch, expected string but got number') + + lines =<< trim END + var x: number + var y: string + var z: string + [x, y, z] = [1, '2', 3] + END + CheckDefExecAndScriptFailure(lines, 'E1163: Variable 3: type mismatch, expected string but got number') enddef def Test_assign_linebreak() *** ../vim-8.2.3309/src/testdir/test_vim9_disassemble.vim 2021-08-07 15:05:44.707105779 +0200 --- src/testdir/test_vim9_disassemble.vim 2021-08-07 16:26:24.245576004 +0200 *************** *** 441,450 **** '\d CHECKTYPE list stack\[-1\]\_s*' .. '\d CHECKLEN >= 2\_s*' .. '\d\+ ITEM 0\_s*' .. ! '\d\+ CHECKTYPE string stack\[-1\]\_s*' .. '\d\+ STORE $0\_s*' .. '\d\+ ITEM 1\_s*' .. ! '\d\+ CHECKTYPE string stack\[-1\]\_s*' .. '\d\+ STORE $1\_s*' .. '\d\+ SLICE 2\_s*' .. '\d\+ STORE $2\_s*' .. --- 441,450 ---- '\d CHECKTYPE list stack\[-1\]\_s*' .. '\d CHECKLEN >= 2\_s*' .. '\d\+ ITEM 0\_s*' .. ! '\d\+ CHECKTYPE string stack\[-1\] arg 1\_s*' .. '\d\+ STORE $0\_s*' .. '\d\+ ITEM 1\_s*' .. ! '\d\+ CHECKTYPE string stack\[-1\] arg 2\_s*' .. '\d\+ STORE $1\_s*' .. '\d\+ SLICE 2\_s*' .. '\d\+ STORE $2\_s*' .. *** ../vim-8.2.3309/src/version.c 2021-08-07 15:50:20.183575301 +0200 --- src/version.c 2021-08-07 16:07:40.836714238 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3310, /**/ -- ARTHUR: Then who is your lord? WOMAN: We don't have a lord. ARTHUR: What? DENNIS: I told you. We're an anarcho-syndicalist commune. We take it in turns to act as a sort of executive officer for the week. The Quest for the Holy Grail (Monty Python) /// 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 ///