-
Notifications
You must be signed in to change notification settings - Fork 99
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
Fix: Support self application of Buffer.append
#165
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import Prim "mo:prim"; | |
import B "mo:base/Buffer"; | ||
import I "mo:base/Iter"; | ||
import O "mo:base/Option"; | ||
import Debug "mo:base/Debug"; | ||
|
||
// test repeated growing | ||
let a = B.Buffer<Nat>(3); | ||
|
@@ -92,3 +93,21 @@ func natIterEq(a:I.Iter<Nat>, b:I.Iter<Nat>) : Bool { | |
assert (c.toArray().size() == 2); | ||
assert (c.toVarArray().size() == 2); | ||
}; | ||
|
||
// regression test: self-append does not diverge | ||
{ | ||
let c = B.Buffer<Nat>(0); | ||
let d = B.Buffer<Nat>(0); | ||
|
||
c.add(1); d.add(1); | ||
c.add(2); d.add(2); | ||
c.add(3); d.add(3); | ||
|
||
Debug.print "append test 1: cloning avoids the issue"; | ||
d.append(d.clone()); | ||
Debug.print "append test 2: cloning not necessary"; | ||
c.append(c); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we want to allow this? The result is tied closely (maybe too close) to the evaluation order, e.g. what's the result of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so you dislike option 3. I can understand why. So, do you want to choose options 1 or 2 (see my list)? Or add other design option? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think option 2 makes sense. They can always clone the buffer if they want to self append. I would expect |
||
Debug.print "success"; | ||
|
||
// to do -- two buffers are equal | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
?