Skip to content

Another semantic analysis order bug #21137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kinke opened this issue Apr 2, 2025 · 1 comment
Open

Another semantic analysis order bug #21137

kinke opened this issue Apr 2, 2025 · 1 comment
Labels
Severity:Industry Code that affects the industry Severity:rejects-valid Code that should compile but doesn't

Comments

@kinke
Copy link
Contributor

kinke commented Apr 2, 2025

This testcase is very similar to #21098 - the real-world code hasn't been fixed yet, so this is another dustmite reduction based on DMD stable (with #21132). As before, compiling b.d works, but a.d fails:

$ dmd -o- a.d
phobos.d(47): Error: expression `hasToString!(const(Nullable!(Type[])))` of type `void` does not have a boolean value

a.d:

import b;

b.d:

import phobos : Appender, Nullable;

struct Type {
    Nullable!(Type[]) templateArgs;
}

Type[] parseDeclarations() {
    Appender!(Type[]) members;
    return null;
}

enum ast = parseDeclarations();

phobos.d:

module phobos;



// module std.typecons;

struct Nullable(T)
{
    T _value;

    string toString() const
    {
        Appender!string app;
        formatValue(app, _value);
        return null;
    }
}



// module std.array;

struct Appender(A)
{
    InPlaceAppender!A impl;
}

struct InPlaceAppender(T)
{
    static void toStringImpl(const T[] data)
    {
        string app;
        formatValue(app, data);
    }
}



// module std.format.internal.write;

void formatValue(Writer, T)(Writer w, T val)
{
    static if (is(T == E[], E))
        formatValue(w, val[0]);
    else static if (is(T == struct) || is(T == union))
    {
        static if (hasToString!T)
            int dummy;
        formatValue(w, val.tupleof);
    }
}

template hasToString(T)
{
    static if (is(typeof(
        (T val) {
            val.toString(123);
        })))
    {
        enum hasToString = true;
    }
    else
    {
        enum hasToString = false;
    }
}
@kinke kinke added Severity:rejects-valid Code that should compile but doesn't Severity:Industry Code that affects the industry labels Apr 2, 2025
@kinke
Copy link
Contributor Author

kinke commented Apr 2, 2025

Interestingly, b.d starts failing with the same error when changing

struct Appender(A)
{
    InPlaceAppender!A impl;
}

struct InPlaceAppender(T)
{
    static void toStringImpl(const T[] data)
    {
        string app;
        formatValue(app, data);
    }
}

to

struct Appender(A)
{
    static void toStringImpl(const A[] data)
    {
        string app;
        formatValue(app, data);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Severity:Industry Code that affects the industry Severity:rejects-valid Code that should compile but doesn't
Projects
None yet
Development

No branches or pull requests

1 participant