Skip to content

Commit

Permalink
<test> testing return managed variables from functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiemstar committed Nov 25, 2024
1 parent 779c01f commit 952b904
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/raii.t
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ terra testcopyassignment2()
end
test.eq(testcopyassignment2(), 5)

--generate implementation for __move
terralib.ext.addmissing.__move(A)

printtestheader("raii.t - return from function.")
terra returnone()
var a = A{4}
var a = A{4}:__move() --call __move to move resources into 'a' (make sure copy constructor is not called)
return a
end

Expand All @@ -108,14 +111,16 @@ end
test.eq(testreturnfromfun1(), 4)

printtestheader("raii.t - return tuple from function.")

terra returntwo()
var a = A{4}
var b = A{5}
var a = A{4}:__move() --call __move to move resources into 'a' (make sure copy constructor is not called)
var b = A{5}:__move() --same for 'b'
return a, b
end

terra testreturnfromfun2()
var a, b = returntwo()
return a.data * b.data
end
print(testreturnfromfun2())
test.eq(testreturnfromfun2(), 20)

0 comments on commit 952b904

Please sign in to comment.