瀏覽代碼

fix: 修复了列表迭代错误

listiter的__next__方法在设置__index变量的时候重置了result导致无法返回正常的值

link #10
SongZihuan 4 年之前
父節點
當前提交
7c4809bbe4
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      VirtulMathCore/ofunc/src/listiter.c

+ 8 - 2
VirtulMathCore/ofunc/src/listiter.c

@@ -56,9 +56,15 @@ ResultType listiter_next(OFFICAL_FUNCTIONSIG){
     if (!CHECK_RESULT(result))
         setResultError(E_StopIterException, "Stop Iter", 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else {
+        Result tmp_result;
+        setResultCore(&tmp_result);
         index->value->data.num.num ++;
-        if (addAttributes("__index", false, index, 0, "listiter.next", ap[0].value, result, inter))
-            setResult(result, inter, belong);
+        if (addAttributes("__index", false, index, 0, "listiter.next", ap[0].value, &tmp_result, inter))
+            freeResult(&tmp_result);
+        else {
+            freeResult(result);
+            *result = tmp_result;
+        }
     }
     return result->type;
 }