comparison src/eval.c @ 18968:24941a950cc7 v8.2.0045

patch 8.2.0045: script test fails Commit: https://github.com/vim/vim/commit/ec57ec692eb228ee061824a190d7c451f029c430 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 25 19:33:22 2019 +0100 patch 8.2.0045: script test fails Problem: Script test fails. Solution: For numbers "is" and "isnot" work like "==" and "!=".
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Dec 2019 19:45:03 +0100
parents 6bd715870e32
children 1ebfb46710cd
comparison
equal deleted inserted replaced
18967:10693b01cc98 18968:24941a950cc7
6259 } 6259 }
6260 6260
6261 else if (typ1->v_type == VAR_FUNC || typ2->v_type == VAR_FUNC 6261 else if (typ1->v_type == VAR_FUNC || typ2->v_type == VAR_FUNC
6262 || typ1->v_type == VAR_PARTIAL || typ2->v_type == VAR_PARTIAL) 6262 || typ1->v_type == VAR_PARTIAL || typ2->v_type == VAR_PARTIAL)
6263 { 6263 {
6264 if (type != ETYPE_EQUAL && type != ETYPE_NEQUAL) 6264 if (type != ETYPE_EQUAL && type != ETYPE_NEQUAL
6265 && type != ETYPE_IS && type != ETYPE_ISNOT)
6265 { 6266 {
6266 emsg(_("E694: Invalid operation for Funcrefs")); 6267 emsg(_("E694: Invalid operation for Funcrefs"));
6267 clear_tv(typ1); 6268 clear_tv(typ1);
6268 return FAIL; 6269 return FAIL;
6269 } 6270 }
6304 f1 = tv_get_float(typ1); 6305 f1 = tv_get_float(typ1);
6305 f2 = tv_get_float(typ2); 6306 f2 = tv_get_float(typ2);
6306 n1 = FALSE; 6307 n1 = FALSE;
6307 switch (type) 6308 switch (type)
6308 { 6309 {
6310 case ETYPE_IS:
6309 case ETYPE_EQUAL: n1 = (f1 == f2); break; 6311 case ETYPE_EQUAL: n1 = (f1 == f2); break;
6312 case ETYPE_ISNOT:
6310 case ETYPE_NEQUAL: n1 = (f1 != f2); break; 6313 case ETYPE_NEQUAL: n1 = (f1 != f2); break;
6311 case ETYPE_GREATER: n1 = (f1 > f2); break; 6314 case ETYPE_GREATER: n1 = (f1 > f2); break;
6312 case ETYPE_GEQUAL: n1 = (f1 >= f2); break; 6315 case ETYPE_GEQUAL: n1 = (f1 >= f2); break;
6313 case ETYPE_SMALLER: n1 = (f1 < f2); break; 6316 case ETYPE_SMALLER: n1 = (f1 < f2); break;
6314 case ETYPE_SEQUAL: n1 = (f1 <= f2); break; 6317 case ETYPE_SEQUAL: n1 = (f1 <= f2); break;
6315 case ETYPE_UNKNOWN: 6318 case ETYPE_UNKNOWN:
6316 case ETYPE_IS:
6317 case ETYPE_ISNOT:
6318 case ETYPE_MATCH: 6319 case ETYPE_MATCH:
6319 case ETYPE_NOMATCH: break; // avoid gcc warning 6320 case ETYPE_NOMATCH: break; // avoid gcc warning
6320 } 6321 }
6321 } 6322 }
6322 #endif 6323 #endif
6323 6324
6324 /* 6325 /*
6325 * If one of the two variables is a number, compare as a number. 6326 * If one of the two variables is a number, compare as a number.
6326 * When using "=~" or "!~", always compare as string. 6327 * When using "=~" or "!~", always compare as string.
6327 */ 6328 */
6328 else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER) 6329 else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER)
6329 && type != ETYPE_MATCH && type != ETYPE_NOMATCH) 6330 && type != ETYPE_MATCH && type != ETYPE_NOMATCH)
6330 { 6331 {
6331 n1 = tv_get_number(typ1); 6332 n1 = tv_get_number(typ1);
6332 n2 = tv_get_number(typ2); 6333 n2 = tv_get_number(typ2);
6333 switch (type) 6334 switch (type)
6334 { 6335 {
6336 case ETYPE_IS:
6335 case ETYPE_EQUAL: n1 = (n1 == n2); break; 6337 case ETYPE_EQUAL: n1 = (n1 == n2); break;
6338 case ETYPE_ISNOT:
6336 case ETYPE_NEQUAL: n1 = (n1 != n2); break; 6339 case ETYPE_NEQUAL: n1 = (n1 != n2); break;
6337 case ETYPE_GREATER: n1 = (n1 > n2); break; 6340 case ETYPE_GREATER: n1 = (n1 > n2); break;
6338 case ETYPE_GEQUAL: n1 = (n1 >= n2); break; 6341 case ETYPE_GEQUAL: n1 = (n1 >= n2); break;
6339 case ETYPE_SMALLER: n1 = (n1 < n2); break; 6342 case ETYPE_SMALLER: n1 = (n1 < n2); break;
6340 case ETYPE_SEQUAL: n1 = (n1 <= n2); break; 6343 case ETYPE_SEQUAL: n1 = (n1 <= n2); break;
6341 case ETYPE_UNKNOWN: 6344 case ETYPE_UNKNOWN:
6342 case ETYPE_IS:
6343 case ETYPE_ISNOT:
6344 case ETYPE_MATCH: 6345 case ETYPE_MATCH:
6345 case ETYPE_NOMATCH: break; // avoid gcc warning 6346 case ETYPE_NOMATCH: break; // avoid gcc warning
6346 } 6347 }
6347 } 6348 }
6348 else 6349 else
6354 else 6355 else
6355 i = 0; 6356 i = 0;
6356 n1 = FALSE; 6357 n1 = FALSE;
6357 switch (type) 6358 switch (type)
6358 { 6359 {
6360 case ETYPE_IS:
6359 case ETYPE_EQUAL: n1 = (i == 0); break; 6361 case ETYPE_EQUAL: n1 = (i == 0); break;
6362 case ETYPE_ISNOT:
6360 case ETYPE_NEQUAL: n1 = (i != 0); break; 6363 case ETYPE_NEQUAL: n1 = (i != 0); break;
6361 case ETYPE_GREATER: n1 = (i > 0); break; 6364 case ETYPE_GREATER: n1 = (i > 0); break;
6362 case ETYPE_GEQUAL: n1 = (i >= 0); break; 6365 case ETYPE_GEQUAL: n1 = (i >= 0); break;
6363 case ETYPE_SMALLER: n1 = (i < 0); break; 6366 case ETYPE_SMALLER: n1 = (i < 0); break;
6364 case ETYPE_SEQUAL: n1 = (i <= 0); break; 6367 case ETYPE_SEQUAL: n1 = (i <= 0); break;
6368 n1 = pattern_match(s2, s1, ic); 6371 n1 = pattern_match(s2, s1, ic);
6369 if (type == ETYPE_NOMATCH) 6372 if (type == ETYPE_NOMATCH)
6370 n1 = !n1; 6373 n1 = !n1;
6371 break; 6374 break;
6372 6375
6373 case ETYPE_IS:
6374 case ETYPE_ISNOT:
6375 case ETYPE_UNKNOWN: break; // avoid gcc warning 6376 case ETYPE_UNKNOWN: break; // avoid gcc warning
6376 } 6377 }
6377 } 6378 }
6378 clear_tv(typ1); 6379 clear_tv(typ1);
6379 typ1->v_type = VAR_NUMBER; 6380 typ1->v_type = VAR_NUMBER;