On Monday, 4 April 2016 at 03:28:01 UTC, Yuxuan Shui wrote:
I have encountered a weird bug.
I defined a Set class, which has a opBinary!"-". And somehow
this:
auto tmp = set_a-set_b;
produces different results as this:
set_a = set_a-set_b;
the latter will produce an empty set.
I tried to reduce the source code to get a test case. But this
problem just goes away after removing some code.
Any ideas what I could have done wrong?
A slightly more reduced test case:
struct Set {
void insert(ulong v) {
aa[v] = true;
}
@disable this(this);
bool[ulong] aa;
}
auto clobber(ref Set x, ref Set o) {
Set ret;
ret.aa = x.aa;
return ret;
}
struct XX {
Set a, b, tmp;
this(int n) {
a.insert(1);
//a.aa[1] = true; <--- Swap above line with this doesn't
trigger the bug
tmp = a.clobber(b);
a = a.clobber(b);
}
}
void main(){
import std.stdio;
XX xx = XX(0);
writeln(xx.a.aa.length);
writeln(xx.tmp.aa.length);
}