[Issue 19990] unknown error with missing import

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 4 00:53:18 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19990

Basile-z <b2.temp at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp at gmx.com

--- Comment #1 from Basile-z <b2.temp at gmx.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list