Fixing 18615, how to handle @safe/pure/nothrow test breakage due to object.opEquals?

SimonN eiderdaus at gmail.com
Wed Mar 28 12:56:52 UTC 2018


Hi,

I'm trying to fix Bugzilla 18615, Rebindable!A doesn't use class 
A's opEquals (returns a is b instead) [1]. The fix looks 
reasonably obvious, my code is at [2]. Most of the added lines is 
the unittest; the essence of the fix is:

     struct RebindableCommon(/* ... */)
     {
         // ...
         bool opEquals(ref const(typeof(this)) rhs) const
         {
             return this.original == rhs.original;
         }
     }

But this breaks several existing unittests throughout Phobos 
because the comparison in object.d lacks @safe, @nogc, nothrow 
and pure. For example, unittests in systime.d fail:

     pure function [...]RebindableCommon[...].opEquals cannot call 
impure function object.opEquals
     nothrow function [...]RebindableCommon[...].opEquals may throw
     std/datetime/systime.d(9006): Error: template instance 
`std.typecons.Rebindable!(immutable(TimeZone))` error 
instantiating

I'd rather not add attributes to the Rebindable.opEquals because 
this function sits in a templated struct RebindableCommon, where 
the compiler should deduce attributes automatically.

But I don't want to remove correct attributes from unittests in 
systime.d either.

Can I reasonably continue here to fix 18615?

-- Simon

[1] https://issues.dlang.org/show_bug.cgi?id=18615
[2] 
https://github.com/SimonN/phobos/commit/5a6fc6fd905b02e5ff93f2aaeaee2487fe8b38d0


More information about the Digitalmars-d-learn mailing list