a.d:
```
module a;
struct A {
import b : B;
Nullable!bool z;
}
```
b.d:
```
module b;
import std.typecons : Nullable;
struct B {
import a : A;
A[] a;
}
Nullable!B b() {
return Nullable!B.init;
}
```
Not only does this cause a useless error message, but changing the `import b : B` to `import b` causes this to compile successfully when it probably shouldn't.
Comment #1 by b2.temp — 2019-11-04T00:53:18Z
The real error from a.d should be
"Error: template instance Nullable!bool template Nullable is not defined"
but it leaks for some reason. I can recover it by patching Nullable opEquals.
Its constraint in combination with the template mess of std.format seems to be the cause of this nightmarish ICE.
I've managed to reduce a bit, so the test case becomes:
a.d:
```
module a;
struct A {
import b : B;
Nullable!bool z;
}
```
b.d:
```
module b;
import c : Nullable;
struct B {
import a : A;
A[] a;
}
Nullable!B b() {
return Nullable!B.init;
}
```
c.d:
```
module c;
import std.format;
struct Nullable(T)
{
private T _value;
private bool _isNull = true;
import std.traits : ReturnType;
version(OK)
{
bool opEquals(U)(auto ref const(U) rhs) const
if (is(ReturnType!(get) == rhs)) // OK, good error does not leak
{
return _isNull ? false : rhs == _value;
}
}
else
bool opEquals(U)(auto ref const(U) rhs) const
if (is(typeof(get == rhs))) // NG
{
return _isNull ? false : rhs == _value;
}
string toString()
{
import std.array : appender;
auto app = appender!string();
auto spec = singleSpecLocal("%s");
toString(app, spec);
return app.data;
}
void toString(W)(ref W writer, scope const ref FormatSpec!char fmt)
{
formatValue(writer, _value, fmt);
}
@property ref inout(T) get() inout @safe pure nothrow
{
return _value;
}
alias get this;
}
FormatSpec!Char singleSpecLocal(Char)(Char[] fmt)
{
return FormatSpec!Char .init;
}
```
compiles with dmd a.b b.d c.d to reproduce the ICE
compiles with dmd a.b b.d c.d -version=OK to see the standard, expected failure
Now it's hard to say if phobos Nullable should be fixed or if more investigation will reveal a DMD bug. I think there's definitively one but the test case is still not ideal.
Comment #2 by robert.schadek — 2024-12-13T19:04:09Z