comparison src/eval.c @ 21309:31a3f4d408b9 v8.2.1205

patch 8.2.1205: Vim9: && and || work different when not compiled Commit: https://github.com/vim/vim/commit/8c34ea54ad1ba3ea9a604ba0495669bdd1393d9a Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 13 22:29:02 2020 +0200 patch 8.2.1205: Vim9: && and || work different when not compiled Problem: Vim9: && and || work different when not compiled. Solution: Keep the value.
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Jul 2020 22:30:06 +0200
parents b991565745fb
children 54a304e4dc57
comparison
equal deleted inserted replaced
21308:aade77a021b5 21309:31a3f4d408b9
2194 int evaluate; 2194 int evaluate;
2195 int orig_flags; 2195 int orig_flags;
2196 long result = FALSE; 2196 long result = FALSE;
2197 typval_T var2; 2197 typval_T var2;
2198 int error; 2198 int error;
2199 int vim9script = in_vim9script();
2199 2200
2200 if (evalarg == NULL) 2201 if (evalarg == NULL)
2201 { 2202 {
2202 CLEAR_FIELD(local_evalarg); 2203 CLEAR_FIELD(local_evalarg);
2203 evalarg_used = &local_evalarg; 2204 evalarg_used = &local_evalarg;
2204 } 2205 }
2205 orig_flags = evalarg_used->eval_flags; 2206 orig_flags = evalarg_used->eval_flags;
2206 evaluate = orig_flags & EVAL_EVALUATE; 2207 evaluate = orig_flags & EVAL_EVALUATE;
2207 if (evaluate) 2208 if (evaluate)
2208 { 2209 {
2209 error = FALSE; 2210 if (vim9script)
2210 if (tv_get_number_chk(rettv, &error) != 0) 2211 {
2211 result = TRUE; 2212 result = tv2bool(rettv);
2212 clear_tv(rettv); 2213 }
2213 if (error) 2214 else
2214 return FAIL; 2215 {
2216 error = FALSE;
2217 if (tv_get_number_chk(rettv, &error) != 0)
2218 result = TRUE;
2219 clear_tv(rettv);
2220 if (error)
2221 return FAIL;
2222 }
2215 } 2223 }
2216 2224
2217 /* 2225 /*
2218 * Repeat until there is no following "||". 2226 * Repeat until there is no following "||".
2219 */ 2227 */
2234 /* 2242 /*
2235 * Compute the result. 2243 * Compute the result.
2236 */ 2244 */
2237 if (evaluate && !result) 2245 if (evaluate && !result)
2238 { 2246 {
2239 if (tv_get_number_chk(&var2, &error) != 0) 2247 if (vim9script)
2240 result = TRUE; 2248 {
2241 clear_tv(&var2); 2249 clear_tv(rettv);
2242 if (error) 2250 *rettv = var2;
2243 return FAIL; 2251 result = tv2bool(rettv);
2244 } 2252 }
2245 if (evaluate) 2253 else
2254 {
2255 if (tv_get_number_chk(&var2, &error) != 0)
2256 result = TRUE;
2257 clear_tv(&var2);
2258 if (error)
2259 return FAIL;
2260 }
2261 }
2262 if (evaluate && !vim9script)
2246 { 2263 {
2247 rettv->v_type = VAR_NUMBER; 2264 rettv->v_type = VAR_NUMBER;
2248 rettv->vval.v_number = result; 2265 rettv->vval.v_number = result;
2249 } 2266 }
2250 2267
2292 int orig_flags; 2309 int orig_flags;
2293 int evaluate; 2310 int evaluate;
2294 long result = TRUE; 2311 long result = TRUE;
2295 typval_T var2; 2312 typval_T var2;
2296 int error; 2313 int error;
2314 int vim9script = in_vim9script();
2297 2315
2298 if (evalarg == NULL) 2316 if (evalarg == NULL)
2299 { 2317 {
2300 CLEAR_FIELD(local_evalarg); 2318 CLEAR_FIELD(local_evalarg);
2301 evalarg_used = &local_evalarg; 2319 evalarg_used = &local_evalarg;
2302 } 2320 }
2303 orig_flags = evalarg_used->eval_flags; 2321 orig_flags = evalarg_used->eval_flags;
2304 evaluate = orig_flags & EVAL_EVALUATE; 2322 evaluate = orig_flags & EVAL_EVALUATE;
2305 if (evaluate) 2323 if (evaluate)
2306 { 2324 {
2307 error = FALSE; 2325 if (vim9script)
2308 if (tv_get_number_chk(rettv, &error) == 0) 2326 {
2309 result = FALSE; 2327 result = tv2bool(rettv);
2310 clear_tv(rettv); 2328 }
2311 if (error) 2329 else
2312 return FAIL; 2330 {
2331 error = FALSE;
2332 if (tv_get_number_chk(rettv, &error) == 0)
2333 result = FALSE;
2334 clear_tv(rettv);
2335 if (error)
2336 return FAIL;
2337 }
2313 } 2338 }
2314 2339
2315 /* 2340 /*
2316 * Repeat until there is no following "&&". 2341 * Repeat until there is no following "&&".
2317 */ 2342 */
2332 /* 2357 /*
2333 * Compute the result. 2358 * Compute the result.
2334 */ 2359 */
2335 if (evaluate && result) 2360 if (evaluate && result)
2336 { 2361 {
2337 if (tv_get_number_chk(&var2, &error) == 0) 2362 if (vim9script)
2338 result = FALSE; 2363 {
2339 clear_tv(&var2); 2364 clear_tv(rettv);
2340 if (error) 2365 *rettv = var2;
2341 return FAIL; 2366 result = tv2bool(rettv);
2342 } 2367 }
2343 if (evaluate) 2368 else
2369 {
2370 if (tv_get_number_chk(&var2, &error) == 0)
2371 result = FALSE;
2372 clear_tv(&var2);
2373 if (error)
2374 return FAIL;
2375 }
2376 }
2377 if (evaluate && !vim9script)
2344 { 2378 {
2345 rettv->v_type = VAR_NUMBER; 2379 rettv->v_type = VAR_NUMBER;
2346 rettv->vval.v_number = result; 2380 rettv->vval.v_number = result;
2347 } 2381 }
2348 2382