Mercurial > vim
comparison src/vim9compile.c @ 25634:27cb2e79ccde v8.2.3353
patch 8.2.3353: Vim9: type of argument for negate not checked at compile time
Commit: https://github.com/vim/vim/commit/cd6b4f300189b4920f7ee7f0204338e91210674b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 15 20:36:28 2021 +0200
patch 8.2.3353: Vim9: type of argument for negate not checked at compile time
Problem: Vim9: type of argument for negate not checked at compile time.
Solution: Add a compile time check.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 15 Aug 2021 20:45:04 +0200 |
parents | 6f13d9ea0d04 |
children | 6ed39aa92cb9 |
comparison
equal
deleted
inserted
replaced
25633:4b6c030bda5c | 25634:27cb2e79ccde |
---|---|
4208 --p; | 4208 --p; |
4209 while (VIM_ISWHITE(*p)) | 4209 while (VIM_ISWHITE(*p)) |
4210 --p; | 4210 --p; |
4211 if (*p == '-' || *p == '+') | 4211 if (*p == '-' || *p == '+') |
4212 { | 4212 { |
4213 int negate = *p == '-'; | 4213 int negate = *p == '-'; |
4214 isn_T *isn; | 4214 isn_T *isn; |
4215 | 4215 garray_T *stack = &cctx->ctx_type_stack; |
4216 // TODO: check type | 4216 type_T *type; |
4217 | |
4218 type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; | |
4219 if (need_type(type, &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL) | |
4220 return FAIL; | |
4221 | |
4217 while (p > start && (p[-1] == '-' || p[-1] == '+')) | 4222 while (p > start && (p[-1] == '-' || p[-1] == '+')) |
4218 { | 4223 { |
4219 --p; | 4224 --p; |
4220 if (*p == '-') | 4225 if (*p == '-') |
4221 negate = !negate; | 4226 negate = !negate; |
4222 } | 4227 } |
4223 // only '-' has an effect, for '+' we only check the type | 4228 // only '-' has an effect, for '+' we only check the type |
4224 if (negate) | 4229 if (negate) |
4230 { | |
4225 isn = generate_instr(cctx, ISN_NEGATENR); | 4231 isn = generate_instr(cctx, ISN_NEGATENR); |
4226 else | 4232 if (isn == NULL) |
4227 isn = generate_instr(cctx, ISN_CHECKNR); | 4233 return FAIL; |
4228 if (isn == NULL) | 4234 } |
4229 return FAIL; | |
4230 } | 4235 } |
4231 else if (numeric_only) | 4236 else if (numeric_only) |
4232 { | 4237 { |
4233 ++p; | 4238 ++p; |
4234 break; | 4239 break; |
5807 goto theend; | 5812 goto theend; |
5808 if (generate_FUNCREF(cctx, ufunc) == FAIL) | 5813 if (generate_FUNCREF(cctx, ufunc) == FAIL) |
5809 goto theend; | 5814 goto theend; |
5810 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); | 5815 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); |
5811 } | 5816 } |
5812 // TODO: warning for trailing text? | |
5813 | 5817 |
5814 theend: | 5818 theend: |
5815 vim_free(lambda_name); | 5819 vim_free(lambda_name); |
5816 return r == FAIL ? NULL : (char_u *)""; | 5820 return r == FAIL ? NULL : (char_u *)""; |
5817 } | 5821 } |
5850 type_T *type) | 5854 type_T *type) |
5851 { | 5855 { |
5852 switch (dest) | 5856 switch (dest) |
5853 { | 5857 { |
5854 case dest_option: | 5858 case dest_option: |
5855 // TODO: check the option exists | |
5856 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type); | 5859 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type); |
5857 break; | 5860 break; |
5858 case dest_global: | 5861 case dest_global: |
5859 if (vim_strchr(name, AUTOLOAD_CHAR) == NULL) | 5862 if (vim_strchr(name, AUTOLOAD_CHAR) == NULL) |
5860 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); | 5863 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); |