Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change clone method of collections to consistently return iso^. #279

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/builtin/array.pony
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ class Array[A] is Seq[A]

error

fun clone(): Array[this->A!]^ =>
fun clone(): Array[this->A!] iso^ =>
"""
Clone the array.
"""
let out = Array[this->A!](_size)
let size' = _size
let out = recover iso Array[this->A!](size') end
_ptr._copy_to(out._ptr, _size)
out

Expand Down
4 changes: 2 additions & 2 deletions packages/collections/list.pony
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ class List[A] is Seq[A]

this

fun clone(): List[this->A!]^ =>
fun clone(): List[this->A!] iso^ =>
"""
Clone the list.
"""
let out = List[this->A!]
let out = recover iso List[this->A!] end

for v in values() do
out.push(v)
Expand Down
5 changes: 3 additions & 2 deletions packages/collections/map.pony
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ class HashMap[K, V, H: HashFunction[K] val]
this

fun clone[H2: HashFunction[this->K!] val = H]():
HashMap[this->K!, this->V!, H2]^
HashMap[this->K!, this->V!, H2] iso^
=>
"""
Create a clone. The key and value types may be different due to aliasing
and viewpoint adaptation.
"""
let r = HashMap[this->K!, this->V!, H2](_size)
let size' = _size
let r = recover iso HashMap[this->K!, this->V!, H2](size') end

for (k, v) in pairs() do
r(k) = v
Expand Down
5 changes: 3 additions & 2 deletions packages/collections/set.pony
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ class HashSet[A, H: HashFunction[A!] val] is Ordered[HashSet[A, H] box]
end
r

fun clone[K: HashFunction[this->A!] val = H](): HashSet[this->A!, K]^ =>
fun clone[K: HashFunction[this->A!] val = H](): HashSet[this->A!, K] iso^ =>
"""
Create a clone. The element type may be different due to aliasing and
viewpoint adaptation.
"""
let r = HashSet[this->A!, K](size())
let size' = size()
let r = recover HashSet[this->A!, K](size') end

for value in values() do
r.set(value)
Expand Down