comparison src/eval.c @ 8635:3a38d465f731 v7.4.1607

commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 19 19:38:12 2016 +0100 patch 7.4.1607 Problem: Comparing a function that exists on two dicts is not backwards compatible. (Thinca) Solution: Only compare the function, not what the partial adds.
author Christian Brabandt <cb@256bit.org>
date Sat, 19 Mar 2016 19:45:05 +0100
parents 80d78e1ab787
children ff41ece2e4b8
comparison
equal deleted inserted replaced
8634:416fa8415ada 8635:3a38d465f731
4553 } 4553 }
4554 4554
4555 else if (rettv->v_type == VAR_FUNC || var2.v_type == VAR_FUNC 4555 else if (rettv->v_type == VAR_FUNC || var2.v_type == VAR_FUNC
4556 || rettv->v_type == VAR_PARTIAL || var2.v_type == VAR_PARTIAL) 4556 || rettv->v_type == VAR_PARTIAL || var2.v_type == VAR_PARTIAL)
4557 { 4557 {
4558 if (rettv->v_type != var2.v_type 4558 if (type != TYPE_EQUAL && type != TYPE_NEQUAL)
4559 || (type != TYPE_EQUAL && type != TYPE_NEQUAL))
4560 { 4559 {
4561 if (rettv->v_type != var2.v_type) 4560 EMSG(_("E694: Invalid operation for Funcrefs"));
4562 EMSG(_("E693: Can only compare Funcref with Funcref"));
4563 else
4564 EMSG(_("E694: Invalid operation for Funcrefs"));
4565 clear_tv(rettv); 4561 clear_tv(rettv);
4566 clear_tv(&var2); 4562 clear_tv(&var2);
4567 return FAIL; 4563 return FAIL;
4568 } 4564 }
4569 else if (rettv->v_type == VAR_PARTIAL) 4565 n1 = tv_equal(rettv, &var2, FALSE, FALSE);
4570 {
4571 /* Partials are only equal when identical. */
4572 n1 = rettv->vval.v_partial != NULL
4573 && rettv->vval.v_partial == var2.vval.v_partial;
4574 }
4575 else
4576 {
4577 /* Compare two Funcrefs for being equal or unequal. */
4578 if (rettv->vval.v_string == NULL
4579 || var2.vval.v_string == NULL)
4580 n1 = FALSE;
4581 else
4582 n1 = STRCMP(rettv->vval.v_string,
4583 var2.vval.v_string) == 0;
4584 }
4585 if (type == TYPE_NEQUAL) 4566 if (type == TYPE_NEQUAL)
4586 n1 = !n1; 4567 n1 = !n1;
4587 } 4568 }
4588 4569
4589 #ifdef FEAT_FLOAT 4570 #ifdef FEAT_FLOAT
6201 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; 6182 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
6202 char_u *s1, *s2; 6183 char_u *s1, *s2;
6203 static int recursive_cnt = 0; /* catch recursive loops */ 6184 static int recursive_cnt = 0; /* catch recursive loops */
6204 int r; 6185 int r;
6205 6186
6187 /* For VAR_FUNC and VAR_PARTIAL only compare the function name. */
6188 if ((tv1->v_type == VAR_FUNC
6189 || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL))
6190 && (tv2->v_type == VAR_FUNC
6191 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial != NULL)))
6192 {
6193 s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string
6194 : tv1->vval.v_partial->pt_name;
6195 s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string
6196 : tv2->vval.v_partial->pt_name;
6197 return (s1 != NULL && s2 != NULL && STRCMP(s1, s2) == 0);
6198 }
6199
6206 if (tv1->v_type != tv2->v_type) 6200 if (tv1->v_type != tv2->v_type)
6207 return FALSE; 6201 return FALSE;
6208 6202
6209 /* Catch lists and dicts that have an endless loop by limiting 6203 /* Catch lists and dicts that have an endless loop by limiting
6210 * recursiveness to a limit. We guess they are equal then. 6204 * recursiveness to a limit. We guess they are equal then.
6232 ++recursive_cnt; 6226 ++recursive_cnt;
6233 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE); 6227 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE);
6234 --recursive_cnt; 6228 --recursive_cnt;
6235 return r; 6229 return r;
6236 6230
6237 case VAR_FUNC:
6238 return (tv1->vval.v_string != NULL
6239 && tv2->vval.v_string != NULL
6240 && STRCMP(tv1->vval.v_string, tv2->vval.v_string) == 0);
6241
6242 case VAR_PARTIAL:
6243 return tv1->vval.v_partial != NULL
6244 && tv1->vval.v_partial == tv2->vval.v_partial;
6245
6246 case VAR_NUMBER: 6231 case VAR_NUMBER:
6247 return tv1->vval.v_number == tv2->vval.v_number; 6232 return tv1->vval.v_number == tv2->vval.v_number;
6248 6233
6249 case VAR_STRING: 6234 case VAR_STRING:
6250 s1 = get_tv_string_buf(tv1, buf1); 6235 s1 = get_tv_string_buf(tv1, buf1);
6264 #endif 6249 #endif
6265 case VAR_CHANNEL: 6250 case VAR_CHANNEL:
6266 #ifdef FEAT_JOB_CHANNEL 6251 #ifdef FEAT_JOB_CHANNEL
6267 return tv1->vval.v_channel == tv2->vval.v_channel; 6252 return tv1->vval.v_channel == tv2->vval.v_channel;
6268 #endif 6253 #endif
6254 case VAR_FUNC:
6255 case VAR_PARTIAL:
6269 case VAR_UNKNOWN: 6256 case VAR_UNKNOWN:
6270 break; 6257 break;
6271 } 6258 }
6272 6259
6273 /* VAR_UNKNOWN can be the result of a invalid expression, let's say it 6260 /* VAR_UNKNOWN can be the result of a invalid expression, let's say it