File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1348,7 +1348,7 @@ enddef
13481348
13491349def Test_expr5_vim9script_channel ()
13501350 if ! has (' channel' )
1351- MissingFeature ' float '
1351+ MissingFeature ' channel '
13521352 else
13531353 var lines = << trim END
13541354 echo ' a' .. test_null_job ()
@@ -1502,6 +1502,18 @@ def Test_expr6()
15021502
15031503 CheckDefExecAndScriptFailure ([' echo 1 / 0' ], ' E1154' , 1 )
15041504 CheckDefExecAndScriptFailure ([' echo 1 % 0' ], ' E1154' , 1 )
1505+
1506+ lines = << trim END
1507+ var n = 0
1508+ eval 1 / n
1509+ END
1510+ CheckDefExecAndScriptFailure (lines , ' E1154' , 2 )
1511+
1512+ lines = << trim END
1513+ var n = 0
1514+ eval 1 % n
1515+ END
1516+ CheckDefExecAndScriptFailure (lines , ' E1154' , 2 )
15051517enddef
15061518
15071519def Test_expr6_vim9script ()
Original file line number Diff line number Diff line change @@ -755,6 +755,8 @@ static char *(features[]) =
755755
756756static int included_patches [] =
757757{ /* Add new patch number below this line */
758+ /**/
759+ 3309 ,
758760/**/
759761 3308 ,
760762/**/
Original file line number Diff line number Diff line change @@ -3435,13 +3435,22 @@ exec_instructions(ectx_T *ectx)
34353435 typval_T * tv2 = STACK_TV_BOT (-1 );
34363436 varnumber_T arg1 = tv1 -> vval .v_number ;
34373437 varnumber_T arg2 = tv2 -> vval .v_number ;
3438- varnumber_T res ;
3438+ varnumber_T res = 0 ;
3439+ int div_zero = FALSE;
34393440
34403441 switch (iptr -> isn_arg .op .op_type )
34413442 {
34423443 case EXPR_MULT : res = arg1 * arg2 ; break ;
3443- case EXPR_DIV : res = arg1 / arg2 ; break ;
3444- case EXPR_REM : res = arg1 % arg2 ; break ;
3444+ case EXPR_DIV : if (arg2 == 0 )
3445+ div_zero = TRUE;
3446+ else
3447+ res = arg1 / arg2 ;
3448+ break ;
3449+ case EXPR_REM : if (arg2 == 0 )
3450+ div_zero = TRUE;
3451+ else
3452+ res = arg1 % arg2 ;
3453+ break ;
34453454 case EXPR_SUB : res = arg1 - arg2 ; break ;
34463455 case EXPR_ADD : res = arg1 + arg2 ; break ;
34473456
@@ -3451,7 +3460,7 @@ exec_instructions(ectx_T *ectx)
34513460 case EXPR_GEQUAL : res = arg1 >= arg2 ; break ;
34523461 case EXPR_SMALLER : res = arg1 < arg2 ; break ;
34533462 case EXPR_SEQUAL : res = arg1 <= arg2 ; break ;
3454- default : res = 0 ; break ;
3463+ default : break ;
34553464 }
34563465
34573466 -- ectx -> ec_stack .ga_len ;
@@ -3462,6 +3471,12 @@ exec_instructions(ectx_T *ectx)
34623471 }
34633472 else
34643473 tv1 -> vval .v_number = res ;
3474+ if (div_zero )
3475+ {
3476+ SOURCING_LNUM = iptr -> isn_lnum ;
3477+ emsg (_ (e_divide_by_zero ));
3478+ goto on_error ;
3479+ }
34653480 }
34663481 break ;
34673482
You can’t perform that action at this time.
0 commit comments