Thread overview
[Issue 23272] [REG2.099] CTFE error of typeid comparison ==
Dec 20, 2022
Iain Buclaw
Dec 20, 2022
Iain Buclaw
Dec 20, 2022
Adam D. Ruppe
Dec 20, 2022
Dlang Bot
Dec 20, 2022
Iain Buclaw
Dec 20, 2022
Iain Buclaw
July 27, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

johanengelen@weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry, rejects-valid

--
July 27, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

--- Comment #1 from johanengelen@weka.io ---
Workaround is to use `is` instead of `==`.

(`assert (s.caseOfTemplated!(a => typeid(a)) is typeid(string));`)

--
December 20, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@gdcproject.org
          Component|dmd                         |druntime

--- Comment #2 from Iain Buclaw <ibuclaw@gdcproject.org> ---
This is not a compiler regression.

Introduced by: https://github.com/dlang/druntime/pull/3665

--
December 20, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

--- Comment #3 from Iain Buclaw <ibuclaw@gdcproject.org> ---
Possible reduction of the original.
---
alias AliasSeq(TList...) = TList;

template EnumMembers(E)
{
    alias EnumMembers = AliasSeq;
    static foreach (M; __traits(allMembers, E))
        EnumMembers = AliasSeq!(__traits(getMember, E, M));
}

struct SumType(Ts)
{
    mixin(() {
        auto s = "enum Cases : ubyte {";
        return s ~= "unset}\n";
    }());

    Cases which;
    union {
        Ts cases;
    }
}

auto caseOfTemplated(alias func, T)(T s) {
    final switch (s.which) foreach(CASE; EnumMembers!(T.Cases)) {
        case CASE:
            return func(s.cases);
    }
}


void foo() {
    bool validate() {
        SumType!(int) s;
        caseOfTemplated!(a => typeid(a))(s) == typeid(string);
        return true;
    }
    static assert(validate);
}

--
December 20, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

Adam D. Ruppe <destructionator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator@gmail.com

--- Comment #4 from Adam D. Ruppe <destructionator@gmail.com> ---
The code that does it is:

// to bypass any opCast that may be present on the original class.
        return .opEquals!(Object, Object)(*cast(Object*) &lhs, *cast(Object*)
&rhs);


And appears plain `cast() lhs, cast() rhs` instead of the pointer cast will
also bypass opCast so i think this is a fairly easy fix.

--
December 20, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@schveiguy created dlang/dmd pull request #14726 "fix 23272. CTFE comparison of TypeInfo fails" fixing this issue:

- fix 23272. CTFE comparison of TypeInfo fails

https://github.com/dlang/dmd/pull/14726

--
December 20, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

--- Comment #6 from Iain Buclaw <ibuclaw@gdcproject.org> ---
(In reply to Iain Buclaw from comment #3)
> Possible reduction of the original.
Which can be hand simplified further to:
---
struct SumType
{
    int cases;
}

auto caseOfTemplated(alias func, T)(T s)
{
    return func(s.cases);
}

void foo()
{
    auto validate()
    {
        SumType s;
        auto t = caseOfTemplated!(a => typeid(a))(s) == typeid(string);
        return true;
    }
    static assert(validate);
}

--
December 20, 2022
https://issues.dlang.org/show_bug.cgi?id=23272

--- Comment #7 from Iain Buclaw <ibuclaw@gdcproject.org> ---
(In reply to Iain Buclaw from comment #6)
> (In reply to Iain Buclaw from comment #3)
> > Possible reduction of the original.
> Which can be hand simplified further to:
Oh wait, I'm being an idiot.
---
void foo()
{
    auto validate()
    {
        assert(typeid(int) != typeid(string));
        return true;
    }
    static assert(validate);
}

--