Mercurial > vim
comparison src/ex_eval.c @ 25202:e5d85e83a887 v8.2.3137
patch 8.2.3137: Vim9: no error when a line only has a variable name
Commit: https://github.com/vim/vim/commit/c323527d67081cfaff22503d1d282495976c7042
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 10 19:42:03 2021 +0200
patch 8.2.3137: Vim9: no error when a line only has a variable name
Problem: Vim9: no error when a line only has a variable name.
Solution: Give an error when an expression is evaluated without an effect.
(closes #8538)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Jul 2021 19:45:04 +0200 |
parents | 6523cd41fa54 |
children | 078edc1821bf |
comparison
equal
deleted
inserted
replaced
25201:3de8a407c744 | 25202:e5d85e83a887 |
---|---|
206 /* | 206 /* |
207 * When an exception is being thrown, some commands (like conditionals) are | 207 * When an exception is being thrown, some commands (like conditionals) are |
208 * not skipped. Errors in those commands may affect what of the subsequent | 208 * not skipped. Errors in those commands may affect what of the subsequent |
209 * commands are regarded part of catch and finally clauses. Catching the | 209 * commands are regarded part of catch and finally clauses. Catching the |
210 * exception would then cause execution of commands not intended by the | 210 * exception would then cause execution of commands not intended by the |
211 * user, who wouldn't even get aware of the problem. Therefor, discard the | 211 * user, who wouldn't even get aware of the problem. Therefore, discard the |
212 * exception currently being thrown to prevent it from being caught. Just | 212 * exception currently being thrown to prevent it from being caught. Just |
213 * execute finally clauses and terminate. | 213 * execute finally clauses and terminate. |
214 */ | 214 */ |
215 if (did_throw) | 215 if (did_throw) |
216 { | 216 { |
894 void | 894 void |
895 ex_eval(exarg_T *eap) | 895 ex_eval(exarg_T *eap) |
896 { | 896 { |
897 typval_T tv; | 897 typval_T tv; |
898 evalarg_T evalarg; | 898 evalarg_T evalarg; |
899 int name_only = FALSE; | |
900 char_u *p; | |
901 long lnum = SOURCING_LNUM; | |
902 | |
903 if (in_vim9script()) | |
904 { | |
905 char_u *alias; | |
906 | |
907 p = eap->arg; | |
908 get_name_len(&p, &alias, FALSE, FALSE); | |
909 name_only = ends_excmd2(eap->arg, skipwhite(p)); | |
910 vim_free(alias); | |
911 } | |
899 | 912 |
900 fill_evalarg_from_eap(&evalarg, eap, eap->skip); | 913 fill_evalarg_from_eap(&evalarg, eap, eap->skip); |
901 | 914 |
902 if (eval0(eap->arg, &tv, eap, &evalarg) == OK) | 915 if (eval0(eap->arg, &tv, eap, &evalarg) == OK) |
916 { | |
903 clear_tv(&tv); | 917 clear_tv(&tv); |
918 if (in_vim9script() && name_only && lnum == SOURCING_LNUM) | |
919 semsg(_(e_expression_without_effect_str), eap->arg); | |
920 } | |
904 | 921 |
905 clear_evalarg(&evalarg, eap); | 922 clear_evalarg(&evalarg, eap); |
906 } | 923 } |
907 | 924 |
908 /* | 925 /* |
1285 eap->errmsg = _(e_continue); | 1302 eap->errmsg = _(e_continue); |
1286 else | 1303 else |
1287 { | 1304 { |
1288 // Try to find the matching ":while". This might stop at a try | 1305 // Try to find the matching ":while". This might stop at a try |
1289 // conditional not in its finally clause (which is then to be executed | 1306 // conditional not in its finally clause (which is then to be executed |
1290 // next). Therefor, inactivate all conditionals except the ":while" | 1307 // next). Therefore, inactivate all conditionals except the ":while" |
1291 // itself (if reached). | 1308 // itself (if reached). |
1292 idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); | 1309 idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); |
1293 if (idx >= 0 && (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) | 1310 if (idx >= 0 && (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) |
1294 { | 1311 { |
1295 rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); | 1312 rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); |