On 11/1/22 11:40 AM, Keivan Shah wrote:
Hello,
Today I came across a strange bug while using D with `dmd`. I have still
not been able to figure out under what conditions does it happen but it
seems to be a DMD related bug to me. Here is a reproducible snippet of
the code
```D
import std;
alias DG = void delegate();
class TType
{
}
class MyClass
{
this(TType t1, TType, double, double[2], double, double, DG, TType,
TType,
DG, DG, DG, double, double, double, double, double, ulong,
bool)
{
assert(t1 is null); // I am passing null so should be null!
// NOTE: Seems to work in LDC but fails in DMD.
writeln("No Bug!");
}
}
void main()
{
auto tt = new TType;
new MyClass(null, tt, 0, [0, 0], 0, 0, null, null, null, null,
null, null,
0, 0, 0, 0, 0, 0, false);
}
```
The code gives an assertion failure on the current versions of dmd
(reproducible on [run.dlang.io](https://run.dlang.io) as well) and does
not happen when using LDC. The bug seems to be sensitive to the number
of arguments and their types making it reproducible only in very limited
cases. I have tried my best to reduce it to minimum but still does
require these many arguments. The end results seems to me like variables
are shifted i.e. variable 1 gets value of variable 2 and so on, but
don't have enough proof to support this.
100% this is a bug in DMD. It should be filed.
I ran some more tests, removing almost any of the parameters or changing
their types seems to avoid the problem.
I also added a parameter name for the second parameter, and DMD appears
to be in this case passing the parameters in the wrong order (t1 is
actually tt, t2 is null)
You can also remove the `import std`, just the assert is enough.
Please file if you can: https://issues.dlang.org
-Steve