https://issues.dlang.org/show_bug.cgi?id=18672
RazvanN <razvan.nitu1...@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |razvan.nitu1...@gmail.com --- Comment #3 from RazvanN <razvan.nitu1...@gmail.com> --- (In reply to ag0aep6g from comment #2) > (In reply to Seb from comment #1) > > So DMD already does transitively apply @safe, but apparently if it generated > > for associative arrays this generation doesn't work in all cases. > > It's not the associative array. It's just that the generated opAssign isn't > @safe (for no reason): > > ---- > void main() @safe > { > struct ThrowingElement > { > ~this() {} > } > > ThrowingElement aa; > /* Accepted. The destructor is apparently inferred as @safe. */ > aa = aa; > /* Error: @safe function D main cannot call @system generated > function onlineapp.main.ThrowingElement.opAssign */ > } > ---- That's because the generated opAssign is not @safe. Look at [1] : it injects a pointer which is void initialized, after that the function is inferred to be @system. I tried replacing the void initializer with null, or with a new ExpInitializer(loc, new ThisExp(loc)). That solves the current test case, but ends up failing other tests (for reasons unknown) [1] https://github.com/dlang/dmd/blob/master/src/dmd/clone.d#L273 --