From 6709839f9677ce49e3d04bb41428cdb473346ae4 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 3 May 2020 06:05:06 +0000 Subject: [PATCH] fixed another bug in 'in' evaluation --- hawk/lib/run.c | 4 ++-- hawk/t/h-001.hawk | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 2d029aec..d61a0e6b 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -3005,6 +3005,7 @@ static HAWK_INLINE int delete_indexed (hawk_rtx_t* rtx, hawk_val_t* vv, hawk_nde hawk_ooch_t* str = HAWK_NULL; hawk_oow_t len; hawk_ooch_t idxbuf[IDXBUFSIZE]; + hawk_arr_t* arr; hawk_ooi_t idx; @@ -4424,7 +4425,6 @@ static hawk_val_t* eval_binop_in (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t* hawk_ooch_t idxbuf[IDXBUFSIZE]; hawk_nde_t* remidx; idxnde_to_str_idxint_t idxint; - hawk_errnum_t errnum; #if defined(HAWK_ENABLE_GC) if (right->type < HAWK_NDE_NAMED || right->type > HAWK_NDE_ARGIDX) @@ -4494,7 +4494,7 @@ static hawk_val_t* eval_binop_in (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t* } arr = ((hawk_val_arr_t*)ropv)->arr; - res = (idxint.v < 0 || idxint.v > HAWK_ARR_SIZE(arr) || !HAWK_ARR_SLOT(arr, idxint.v))? HAWK_VAL_ZERO: HAWK_VAL_ONE; + res = (idxint.v < 0 || idxint.v >= HAWK_ARR_SIZE(arr) || !HAWK_ARR_SLOT(arr, idxint.v))? HAWK_VAL_ZERO: HAWK_VAL_ONE; break; } diff --git a/hawk/t/h-001.hawk b/hawk/t/h-001.hawk index a254cf67..a03fc186 100644 --- a/hawk/t/h-001.hawk +++ b/hawk/t/h-001.hawk @@ -138,5 +138,25 @@ function main() ensure (hawk::array_size(a), 0, SCRIPTNAME); } + { + @local a, b; + a = hawk::array(); + a[10][20][30] = 20; + b[12][20][30] = 20; + ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, SCRIPTNAME); + ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, SCRIPTNAME); + + b = hawk::map(); + b[10][20][30] = 20; + b[12][20][30] = 20; + ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, SCRIPTNAME); + ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, SCRIPTNAME); + + c = hawk::map(); + c[10,20,30] = "heloo"; + ensure (((10,20,30) in c), 1, SCRIPTNAME); + ensure (((10,30,30) in c), 0, SCRIPTNAME); + } + print "SUCCESS" }