d1b14071e454 — Leonard Ritter a month ago
* further fixes for double drops
2 files changed, 17 insertions(+), 17 deletions(-)

M src/prover.cpp
M testing/test_borrowing.sc
M src/prover.cpp +9 -13
@@ 744,13 744,6 @@ static SCOPES_RESULT(void) move_merge_va
         SCOPES_CHECK_RESULT(drop_values(ctx, mover, todrop));
     }
 
-    // HACK: do not keep returned values visible to parent scopes that are cleaning up
-    if (retdepth == 0) {
-        for (auto id : saved) {
-            ctx.move(id, mover);
-        }
-    }
-
     return {};
 }
 

          
@@ 758,12 751,15 @@ static SCOPES_RESULT(TypedValueRef) move
     int retdepth, TypedValueRef result, const char *by) {
     SCOPES_RESULT_TYPE(TypedValueRef);
     TypedValues values;
-    if (is_returning_value(result->get_type())
-        && split_return_values(values, result)) {
-        SCOPES_CHECK_RESULT(move_merge_values(ctx, result, retdepth, values, by));
-        result = ref(result.anchor(), ArgumentList::from(values));
-    } else {
-        SCOPES_CHECK_RESULT(move_merge_values(ctx, result, retdepth, values, by));
+    auto RT = result->get_type();
+    if (is_returning(RT)) {
+        if (is_returning_value(RT)
+            && split_return_values(values, result)) {
+            SCOPES_CHECK_RESULT(move_merge_values(ctx, result, retdepth, values, by));
+            result = ref(result.anchor(), ArgumentList::from(values));
+        } else {
+            SCOPES_CHECK_RESULT(move_merge_values(ctx, result, retdepth, values, by));
+        }
     }
     return result;
 }

          
M testing/test_borrowing.sc +8 -4
@@ 559,7 559,7 @@ do
     parse (nullof M)
     parse2 (nullof M)
 
-# regression: return in a do-block or label causes double free
+# regression: return in a do-block or label causes double drop
      produces: assertion failed: (_refcount >= 0)
 fn testfunc ()
     fn testf ()

          
@@ 571,11 571,15 @@ testfunc;
 One.test-refcount-balanced;
 
 # error: cannot access value of type (uniqueof One 1000) because it has been moved
-#fn testfunc ()
+     also produces double drops
+fn testfunc ()
     label ok
         label ok2
+            if false
+                merge ok2 (One 305)
             merge ok (One 303)
-#testfunc;
-#One.test-refcount-balanced;
+    ;
+testfunc;
+One.test-refcount-balanced;
 
 ;
  No newline at end of file