Consider a type that I want to deprecate:
```d
struct T {
int x;
}
unittest {
assert(T(1) == T(1));
}
```
If I deprecate T, then I also must deprecate the unittest, or else I get deprecation messages (as expected).
However, if I then use the `-checkaction=context` command line parameter, there are now deprecation messages because the compiler is trying to format the string using the deprecated type:
```
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(65): Deprecation: struct `onlineapp.T` is deprecated
onlineapp.d(7): instantiated from here: `_d_assert_fail!(T)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(65): Deprecation: struct `onlineapp.T` is deprecated
onlineapp.d(7): instantiated from here: `_d_assert_fail!(T)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(522): Deprecation: struct `onlineapp.T` is deprecated
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(75): instantiated from here: `miniFormatFakeAttributes!(T)`
onlineapp.d(7): instantiated from here: `_d_assert_fail!(T)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(176): Deprecation: struct `onlineapp.T` is deprecated
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(524): instantiated from here: `miniFormat!(T)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(75): instantiated from here: `miniFormatFakeAttributes!(T)`
onlineapp.d(7): instantiated from here: `_d_assert_fail!(T)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(425): Deprecation: struct `onlineapp.T` is deprecated
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(404): instantiated from here: `formatMembers!(T)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(524): instantiated from here: `miniFormat!(T)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/dassert.d(75): instantiated from here: `miniFormatFakeAttributes!(T)`
onlineapp.d(7): instantiated from here: `_d_assert_fail!(T)`
```
I propose that checkaction=context does not apply for comparisons involving deprecated types, or that it doesn't apply inside deprecated functions/unittests.
The workaround is to change the assert to `assert((T(1) == T(1)) == true);` But this is quite tedious to enact. I'd rather just have the compiler do it for me.
Comment #1 by robert.schadek — 2024-12-13T19:27:57Z