Skip to content

Commit 7517ffd

Browse files
committed
patch 8.2.1446: Vim9: line number in error message is not correct
Problem: Vim9: line number in error message is not correct. Solution: Set SOURCING_LNUM before calling emsg(). (closes #6708)
1 parent c4ce36d commit 7517ffd

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/testdir/test_vim9_func.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ def Test_error_reporting()
10451045
call writefile(lines, 'Xdef')
10461046
try
10471047
source Xdef
1048+
assert_report('should have failed')
10481049
catch /E476:/
10491050
assert_match('Invalid command: invalid', v:exception)
10501051
assert_match(', line 3$', v:throwpoint)
@@ -1064,11 +1065,30 @@ def Test_error_reporting()
10641065
call writefile(lines, 'Xdef')
10651066
try
10661067
source Xdef
1068+
assert_report('should have failed')
10671069
catch /E476:/
10681070
assert_match('Invalid command: invalid', v:exception)
10691071
assert_match(', line 4$', v:throwpoint)
10701072
endtry
10711073

1074+
lines =<< trim END
1075+
vim9script
1076+
def Func()
1077+
let db = #{foo: 1, bar: 2}
1078+
# comment
1079+
let x = db.asdf
1080+
enddef
1081+
defcompile
1082+
Func()
1083+
END
1084+
call writefile(lines, 'Xdef')
1085+
try
1086+
source Xdef
1087+
assert_report('should have failed')
1088+
catch /E716:/
1089+
assert_match('_Func, line 3$', v:throwpoint)
1090+
endtry
1091+
10721092
call delete('Xdef')
10731093
enddef
10741094

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1446,
757759
/**/
758760
1445,
759761
/**/

src/vim9execute.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ call_def_function(
10271027
tv = STACK_TV_BOT(idx - count);
10281028
if (tv->v_type == VAR_CHANNEL || tv->v_type == VAR_JOB)
10291029
{
1030+
SOURCING_LNUM = iptr->isn_lnum;
10301031
emsg(_(e_inval_string));
10311032
break;
10321033
}
@@ -1121,6 +1122,7 @@ call_def_function(
11211122

11221123
if (di == NULL)
11231124
{
1125+
SOURCING_LNUM = iptr->isn_lnum;
11241126
semsg(_(e_undefvar), name);
11251127
goto on_error;
11261128
}
@@ -1169,6 +1171,7 @@ call_def_function(
11691171

11701172
if (di == NULL)
11711173
{
1174+
SOURCING_LNUM = iptr->isn_lnum;
11721175
semsg(_("E121: Undefined variable: %c:%s"),
11731176
namespace, iptr->isn_arg.string);
11741177
goto on_error;
@@ -1326,6 +1329,7 @@ call_def_function(
13261329
clear_tv(tv);
13271330
if (msg != NULL)
13281331
{
1332+
SOURCING_LNUM = iptr->isn_lnum;
13291333
emsg(_(msg));
13301334
goto on_error;
13311335
}
@@ -1421,6 +1425,7 @@ call_def_function(
14211425
lidx = list->lv_len + lidx;
14221426
if (lidx < 0 || lidx > list->lv_len)
14231427
{
1428+
SOURCING_LNUM = iptr->isn_lnum;
14241429
semsg(_(e_listidx), lidx);
14251430
goto on_error;
14261431
}
@@ -1457,6 +1462,7 @@ call_def_function(
14571462

14581463
if (dict == NULL)
14591464
{
1465+
SOURCING_LNUM = iptr->isn_lnum;
14601466
emsg(_(e_dictionary_not_set));
14611467
goto on_error;
14621468
}
@@ -1586,6 +1592,7 @@ call_def_function(
15861592
item = dict_find(dict, tv->vval.v_string, -1);
15871593
if (item != NULL)
15881594
{
1595+
SOURCING_LNUM = iptr->isn_lnum;
15891596
semsg(_(e_duplicate_key), tv->vval.v_string);
15901597
dict_unref(dict);
15911598
goto on_error;
@@ -1749,6 +1756,7 @@ call_def_function(
17491756
if (tv->v_type == VAR_PARTIAL)
17501757
{
17511758
// TODO: use a garray_T on ectx.
1759+
SOURCING_LNUM = iptr->isn_lnum;
17521760
emsg("Multiple closures not supported yet");
17531761
goto failed;
17541762
}
@@ -1852,6 +1860,7 @@ call_def_function(
18521860
case ISN_PUSHEXC:
18531861
if (current_exception == NULL)
18541862
{
1863+
SOURCING_LNUM = iptr->isn_lnum;
18551864
iemsg("Evaluating catch while current_exception is NULL");
18561865
goto failed;
18571866
}
@@ -2175,7 +2184,8 @@ call_def_function(
21752184
case EXPR_DIV: f1 = f1 / f2; break;
21762185
case EXPR_SUB: f1 = f1 - f2; break;
21772186
case EXPR_ADD: f1 = f1 + f2; break;
2178-
default: emsg(_(e_modulus));
2187+
default: SOURCING_LNUM = iptr->isn_lnum;
2188+
emsg(_(e_modulus));
21792189
goto on_error;
21802190
}
21812191
clear_tv(tv1);
@@ -2228,6 +2238,7 @@ call_def_function(
22282238
tv = STACK_TV_BOT(-2);
22292239
if (tv->v_type != VAR_STRING)
22302240
{
2241+
SOURCING_LNUM = iptr->isn_lnum;
22312242
emsg(_(e_stringreq));
22322243
goto on_error;
22332244
}
@@ -2236,6 +2247,7 @@ call_def_function(
22362247
tv = STACK_TV_BOT(-1);
22372248
if (tv->v_type != VAR_NUMBER)
22382249
{
2250+
SOURCING_LNUM = iptr->isn_lnum;
22392251
emsg(_(e_number_exp));
22402252
goto on_error;
22412253
}
@@ -2266,6 +2278,7 @@ call_def_function(
22662278
tv = STACK_TV_BOT(-2);
22672279
if (tv->v_type != VAR_LIST)
22682280
{
2281+
SOURCING_LNUM = iptr->isn_lnum;
22692282
emsg(_(e_listreq));
22702283
goto on_error;
22712284
}
@@ -2274,13 +2287,15 @@ call_def_function(
22742287
tv = STACK_TV_BOT(-1);
22752288
if (tv->v_type != VAR_NUMBER)
22762289
{
2290+
SOURCING_LNUM = iptr->isn_lnum;
22772291
emsg(_(e_number_exp));
22782292
goto on_error;
22792293
}
22802294
n = tv->vval.v_number;
22812295
clear_tv(tv);
22822296
if ((li = list_find(list, n)) == NULL)
22832297
{
2298+
SOURCING_LNUM = iptr->isn_lnum;
22842299
semsg(_(e_listidx), n);
22852300
goto on_error;
22862301
}
@@ -2354,6 +2369,7 @@ call_def_function(
23542369

23552370
if ((di = dict_find(dict, key, -1)) == NULL)
23562371
{
2372+
SOURCING_LNUM = iptr->isn_lnum;
23572373
semsg(_(e_dictkey), key);
23582374
goto on_error;
23592375
}
@@ -2378,6 +2394,7 @@ call_def_function(
23782394
tv = STACK_TV_BOT(-1);
23792395
if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL)
23802396
{
2397+
SOURCING_LNUM = iptr->isn_lnum;
23812398
emsg(_(e_dictreq));
23822399
goto on_error;
23832400
}
@@ -2386,6 +2403,7 @@ call_def_function(
23862403
if ((di = dict_find(dict, iptr->isn_arg.string, -1))
23872404
== NULL)
23882405
{
2406+
SOURCING_LNUM = iptr->isn_lnum;
23892407
semsg(_(e_dictkey), iptr->isn_arg.string);
23902408
goto on_error;
23912409
}
@@ -2405,6 +2423,7 @@ call_def_function(
24052423
#endif
24062424
)
24072425
{
2426+
SOURCING_LNUM = iptr->isn_lnum;
24082427
emsg(_(e_number_exp));
24092428
goto on_error;
24102429
}
@@ -2441,6 +2460,7 @@ call_def_function(
24412460
|| (tv->v_type == VAR_FUNC
24422461
&& ct->ct_type == VAR_PARTIAL)))
24432462
{
2463+
SOURCING_LNUM = iptr->isn_lnum;
24442464
semsg(_("E1029: Expected %s but got %s"),
24452465
vartype_name(ct->ct_type),
24462466
vartype_name(tv->v_type));
@@ -2461,6 +2481,7 @@ call_def_function(
24612481
|| (list->lv_len > min_len
24622482
&& !iptr->isn_arg.checklen.cl_more_OK))
24632483
{
2484+
SOURCING_LNUM = iptr->isn_lnum;
24642485
semsg(_("E1093: Expected %d items but got %d"),
24652486
min_len, list == NULL ? 0 : list->lv_len);
24662487
goto on_error;

0 commit comments

Comments
 (0)