-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Closed
Description
The following program prints "0\n0\n", when it should print "0\n":
resource echo(x: {mut a: int}) {
io::println(#fmt("%d", x.a));
x.a += 1;
}
fn main() {
let x = [echo({mut a: 0})];
let y = x;
}
The same effect occurs if you rename y to _y to eliminate the unused variable warning. The same effect does not occur if you use y, eg the following program has correct behavior:
resource echo(x: {mut a: int}) {
io::println(#fmt("%d", x.a));
x.a += 1;
}
fn main() {
let x = [echo({mut a: 0})];
let y = x;
y;
}
The use of a record with a mutable field is also not essential to the bug; I used it to demonstrate that the bug is actually due to copying, and not running the destructor twice on the same value.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels