comparison src/vim9compile.c @ 21881:675bf9475fff v8.2.1490

patch 8.2.1490: Vim9: using /= with float and number doesn't work Commit: https://github.com/vim/vim/commit/93ad14710bdf77591f927a2b244bba6a8cbc7706 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 19 22:02:41 2020 +0200 patch 8.2.1490: Vim9: using /= with float and number doesn't work Problem: Vim9: using /= with float and number doesn't work. Solution: Better support assignment with operator. (closes https://github.com/vim/vim/issues/6742)
author Bram Moolenaar <Bram@vim.org>
date Wed, 19 Aug 2020 22:15:04 +0200
parents b530ead4265a
children a427f5f26419
comparison
equal deleted inserted replaced
21880:0520437529d0 21881:675bf9475fff
4921 lvar->lv_type = &t_dict_any; 4921 lvar->lv_type = &t_dict_any;
4922 else 4922 else
4923 lvar->lv_type = stacktype; 4923 lvar->lv_type = stacktype;
4924 } 4924 }
4925 } 4925 }
4926 else 4926 else if (*op == '=')
4927 { 4927 {
4928 type_T *use_type = lvar->lv_type; 4928 type_T *use_type = lvar->lv_type;
4929 4929
4930 // without operator type is here, otherwise below
4930 if (has_index) 4931 if (has_index)
4931 { 4932 {
4932 use_type = use_type->tt_member; 4933 use_type = use_type->tt_member;
4933 if (use_type == NULL) 4934 if (use_type == NULL)
4934 use_type = &t_void; 4935 use_type = &t_void;
4935 } 4936 }
4936 if (need_type(stacktype, use_type, -1, cctx, FALSE) 4937 if (need_type(stacktype, use_type, -1, cctx, FALSE)
4937 == FAIL) 4938 == FAIL)
4938 goto theend; 4939 goto theend;
4939 } 4940 }
4940 } 4941 }
4941 else if (*p != '=' && need_type(stacktype, member_type, -1, 4942 else if (*p != '=' && need_type(stacktype, member_type, -1,
4942 cctx, FALSE) == FAIL) 4943 cctx, FALSE) == FAIL)
5006 if (cctx->ctx_skip == SKIP_YES) 5007 if (cctx->ctx_skip == SKIP_YES)
5007 break; 5008 break;
5008 5009
5009 if (oplen > 0 && *op != '=') 5010 if (oplen > 0 && *op != '=')
5010 { 5011 {
5011 type_T *expected = &t_number; 5012 type_T *expected;
5012 type_T *stacktype; 5013 type_T *stacktype;
5013
5014 // TODO: if type is known use float or any operation
5015 // TODO: check operator matches variable type
5016 5014
5017 if (*op == '.') 5015 if (*op == '.')
5018 expected = &t_string; 5016 expected = &t_string;
5019 else if (*op == '+') 5017 else
5020 expected = member_type; 5018 expected = member_type;
5021 stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; 5019 stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
5022 if (need_type(stacktype, expected, -1, cctx, FALSE) == FAIL) 5020 if (
5021 #ifdef FEAT_FLOAT
5022 // If variable is float operation with number is OK.
5023 !(expected == &t_float && stacktype == &t_number) &&
5024 #endif
5025 need_type(stacktype, expected, -1, cctx, FALSE) == FAIL)
5023 goto theend; 5026 goto theend;
5024 5027
5025 if (*op == '.') 5028 if (*op == '.')
5026 { 5029 {
5027 if (generate_instr_drop(cctx, ISN_CONCAT, 1) == NULL) 5030 if (generate_instr_drop(cctx, ISN_CONCAT, 1) == NULL)
5032 if (generate_add_instr(cctx, 5035 if (generate_add_instr(cctx,
5033 operator_type(member_type, stacktype), 5036 operator_type(member_type, stacktype),
5034 member_type, stacktype) == FAIL) 5037 member_type, stacktype) == FAIL)
5035 goto theend; 5038 goto theend;
5036 } 5039 }
5037 else 5040 else if (generate_two_op(cctx, op) == FAIL)
5038 { 5041 goto theend;
5039 isn_T *isn = generate_instr_drop(cctx, ISN_OPNR, 1);
5040
5041 if (isn == NULL)
5042 goto theend;
5043 switch (*op)
5044 {
5045 case '-': isn->isn_arg.op.op_type = EXPR_SUB; break;
5046 case '*': isn->isn_arg.op.op_type = EXPR_MULT; break;
5047 case '/': isn->isn_arg.op.op_type = EXPR_DIV; break;
5048 case '%': isn->isn_arg.op.op_type = EXPR_REM; break;
5049 }
5050 }
5051 } 5042 }
5052 5043
5053 if (has_index) 5044 if (has_index)
5054 { 5045 {
5055 int r; 5046 int r;